New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm not able to write on the DB with the save () method #708

Open
danilorosso opened this Issue Dec 15, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@danilorosso

danilorosso commented Dec 15, 2016

Hi,
I'm trying to use Sugar ORM in my Android App, but without success.

My project consists of the Activity with View to request the data to be loaded into the DB, and an Activity without View to upload the data to the DB with the save () method of Sugar package.

The following is my code that goes into error when call save() metod:

package com.example.danilo.genealogia;

/**

  • Created by danilo on 06/12/16.
    */

public class InsertG extends android.app.Application{
Gana gana;
public InsertG(){
}

public String setValues(String cognome,String nome,String mF,String ggN,String mmN,String annoN,String luogoNascita) {
    System.out.println(cognome);
    System.out.println(nome);
    System.out.println(mF);
    System.out.println(ggN+"/"+mmN+"/"+annoN);



    gana = new Gana();

        gana.tiprec = "N";
        gana.cognome = cognome;
        gana.nome = nome;
        gana.mF = mF;
        gana.ggN = ggN;
        gana.mmN = mmN;
        gana.annoN = annoN;
        gana.luogoNascita = luogoNascita;

        gana.save();


    return("FATTO");
    }
}

Here the list of errors

              --------- beginning of crash

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.danilo.genealogia3, PID: 2515
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.orm.Database com.orm.SugarApp.getDatabase()' on a null object reference
at com.orm.SugarRecord.save(SugarRecord.java:47)
at com.example.danilo.genealogia.InsertG.setValues(InsertG.java:36)
at com.example.danilo.genealogia.NuovoG.inserisci(NuovoG.java:35)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Device Nexus_5_API_25 [emulator-5554]disconnected, monitoring stopped.
Application terminated.

Here table statement:

package com.example.danilo.genealogia;

import com.orm.SugarRecord;

/**

  • Created by danilo on 11/12/16.
    */

public class Gana extends SugarRecord {
String tiprec;
String nome;
String cognome;
String ggN;
String mmN;
String annoN;
String luogoNascita;
String mF;
String vD;
String ggM;
String mmM;
String annoM;
String luogoMorte;
String luogoSepoltura;
String indS;

public Gana(){
}

}

and here the project manifest:

<application
    android:theme="@style/Theme.AppCompat.Light">
    android:name="com.orm.SugarApp" >  <!--Use this attribute verbatim-->
    <meta-data android:name="DATABASE" android:value="gensql.db" />
    <meta-data android:name="VERSION" android:value="1" />
    <meta-data android:name="QUERY_LOG" android:value="true" />
    <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example.danilo.genealogia" />
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".NuovoG" />
    <activity android:name=".ElencoG" />
    <activity
        android:name=".Cerca"
        android:label="@string/title_activity_cerca"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
    <activity android:name=".CercaGana" />
    <activity android:name=".GestioneG" />
    <activity android:name=".Foto" />
    <activity android:name=".Scheda" />
    <activity android:name=".AlberoTot" />
    <activity android:name=".AlberoParz" />
    <activity android:name=".Famiglia" />
    <!--activity android:name=".ModificaG" /-->
    <!--activity android:name=".DeleteG" /-->
    <activity android:name=".Partner" />
    <activity android:name=".ElencoF" />
    <activity android:name=".ModificaF" />
    <activity android:name=".DeleteF" />
    <activity android:name=".ModificaP" />
    <activity android:name=".deleteP"></activity>
</application>

Where am I wrong?
Thank you in advance for any suggestions.

best regards

danilo

@danilorosso

This comment has been minimized.

Show comment
Hide comment
@danilorosso

danilorosso Dec 16, 2016

why was closed?

danilorosso commented Dec 16, 2016

why was closed?

@seyidkanan

This comment has been minimized.

Show comment
Hide comment
@seyidkanan

seyidkanan Jan 13, 2017

Ar u add model getter setter? or Ar u use constructor with arguments?

seyidkanan commented Jan 13, 2017

Ar u add model getter setter? or Ar u use constructor with arguments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment