ActiveAndroid icon indicating copy to clipboard operation
ActiveAndroid copied to clipboard

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.activeandroid.TableInfo.getIdName()' on a null object reference

Open sebastiandeutsch opened this issue 9 years ago • 45 comments

Hi,

I'm getting a strange NullPointer exception on a fresh application that I'm creating (AndroidStudio 2/Android 6.0.1). Any thing that I'm missing?

Best

Sebastian

sebastiandeutsch avatar Mar 21 '16 17:03 sebastiandeutsch

I am also getting this error.

sakkeerhussain avatar Mar 22 '16 16:03 sakkeerhussain

I actually switched to Realm. It seems ActiveAndroid is not maintained anymore.

sebastiandeutsch avatar Mar 22 '16 16:03 sebastiandeutsch

Maybe @svendvd could give us insights how his fix works :-)

sebastiandeutsch avatar Mar 22 '16 16:03 sebastiandeutsch

It was working fine for me before now I updated DB model and am getting the above error. my app is almost complete.

sakkeerhussain avatar Mar 22 '16 17:03 sakkeerhussain

Hi @sebastiandeutsch

I fixed my issue. It was because my model classes where not loading properly in to active android.

sakkeerhussain avatar Mar 22 '16 17:03 sakkeerhussain

Hi this is my simple workaround. https://github.com/pardom/ActiveAndroid/pull/462

svendvd avatar Mar 22 '16 18:03 svendvd

Hello, this is a huge blocker for us. Any chance for the fix soon ?

Thanks.

savicprvoslav avatar Mar 25 '16 12:03 savicprvoslav

@sakkeerhussain Can you tell me, how do you fix it?

Christ9038 avatar Apr 05 '16 15:04 Christ9038

@Christ9038 I was added my models name in manifest with AA_Model tag. Even though Model names are correct the path to the model classes where not correct. I just corrected that and solved my issue.

sakkeerhussain avatar Apr 06 '16 14:04 sakkeerhussain

@sakkeerhussain It solved my issue! Thank you so much.

Christ9038 avatar Apr 06 '16 14:04 Christ9038

@Christ9038 Great to here this from you.

Thanks, Sakkeer Hussain

On 6 April 2016 at 19:48, Christ9038 [email protected] wrote:

@sakkeerhussain https://github.com/sakkeerhussain It solved my issue! Thank you so much.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/pardom/ActiveAndroid/issues/461#issuecomment-206392810

sakkeerhussain avatar Apr 06 '16 18:04 sakkeerhussain

Hi @sakkeerhussain do you mean something like this? <meta-data android:name="AA_Model" android:value="ModelName"/>

soygustavo avatar Apr 07 '16 20:04 soygustavo

The same happened with me when I upgraded to Android Studio 2.0 I think this happens if we use gradle 2.0 as build tools. My app is working fine with gradle 1.3 as build tools. Could someone confirm this?

rohanraarora avatar Apr 08 '16 02:04 rohanraarora

Is it AA_Model or AA_MODELS ? I tried both of them but still its not working.. Upgraded to Android Studio 2.0

xahy avatar Apr 08 '16 04:04 xahy

I have same problem with upgrade on 2.0. I've updated manifest like this:

<meta-data android:name="AA_DB_NAME" android:value="1.0.0.0.1" />
 <meta-data android:name="AA_DB_VERSION" android:value="20" />

And it works

UPD: also i've changed back gradle version to 1.5

strgen avatar Apr 08 '16 05:04 strgen

@strgen what a db name hehe. I re-installed android 1.5.1 and its working just like before. I think I will release the app for now and later will change to Realm since AA is discontinued.

xahy avatar Apr 08 '16 05:04 xahy

@xahy, what database name in your opinion is right? :) I'm using it for test when you need clear db.

strgen avatar Apr 08 '16 05:04 strgen

have same problem with upgrade on Android Studio 2.0. the sModelInfo is empty.

xushaojie avatar Apr 08 '16 06:04 xushaojie

@sebastiandeutsch @xahy solved !

If your project have ModelAxx, ModelBxx, ModelCxx...

you can write at Manifest.xml just like:

<meta-data android:name="AA_MODELS" android:value="com.my.db.ModelAxx, com.my.db.ModelBxx, com.my.db.ModelCxx />

xushaojie avatar Apr 08 '16 06:04 xushaojie

@xushaojie I tried that, and still it was showing the same error. I can install Studio 2.0 again and try that. Will post here if its working.

@strgen 🤓

xahy avatar Apr 08 '16 07:04 xahy

@xahy contains all models? check code again.

xushaojie avatar Apr 08 '16 07:04 xushaojie

@soygustavo like this

include full path to your model classes.

sakkeerhussain avatar Apr 08 '16 10:04 sakkeerhussain

@sakkeerhussain It resolves the issue but slows down the startup of my app a lot. Another solution is to disable the Instant Run in Android Studio.

rohanraarora avatar Apr 09 '16 12:04 rohanraarora

@xushaojie thanks your solution is work ! 💃

billyriantono avatar Apr 11 '16 03:04 billyriantono

@sakkeerhussain thanks but now i have another error

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.myproject.dataStorage.Preference.getValue()' on a null object reference

android.database.sqlite.SQLiteException: no such table: Preferences (code 1): , while compiling: SELECT * FROM Preferences

any ideas?

UPDATE: i fix it changing this <meta-data android:name="AA_DB_VERSION" android:value="2" /> for this <meta-data android:name="AA_DB_VERSION" android:value="3" />

soygustavo avatar Apr 11 '16 15:04 soygustavo

Disable instant run will fix the problem. Have to ways to do this. One in preferences on android studio. and other way to change your gradle version to 2.0.0 (this also remove instant run)

ChathuraHettiarachchi avatar May 10 '16 10:05 ChathuraHettiarachchi

i have solved my issue

if u r using ur own Application class than initialize ActiveAndroid in oncreate method

ActiveAndroid.initialize(this);

complete code

public class MyApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();
    ActiveAndroid.initialize(this);
}

}

zulqer avatar Sep 14 '16 13:09 zulqer

thanks @xushaojie works for me

derohimat avatar Nov 23 '16 16:11 derohimat

adding AA_MODELS to Manifest did solve this issue.

pynixwang avatar Jan 13 '17 07:01 pynixwang

@pynixwang Can you give me an example of how you put the paths of your clases , i've tried something like "com.mypackage.models.db.ClassName1,com.mypackage.models.db.ClassName2"

I'm using Android studio 2.2.3, Instant run disabled, Gradle version 1.5.0.

Error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.activeandroid.TableInfo.getTableName()' on a null object reference

Gustavol95 avatar Jan 13 '17 17:01 Gustavol95

@Gustavol95 just the class name contain package,but gradle version is 2.1.4。

pynixwang avatar Jan 14 '17 04:01 pynixwang

@Gustavol95 try to upgrade your gradle version and enable instant run,if I disable instant run ,there is no issue,but install apk everytime is not acceptable,it is too slow.

pynixwang avatar Jan 14 '17 04:01 pynixwang

gettting every time same error :

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.activeandroid.TableInfo.getIdName()' on a null object reference

PratikPagada avatar Jan 18 '17 20:01 PratikPagada

@PratikPagada see my code.maybe useful.

xushaojie avatar Jan 19 '17 06:01 xushaojie

try with this

add this code in AndroidManifest.xml


 <meta-data
            android:name="AA_DB_NAME"
            android:value="MyDb.db"/>

<meta-data
            android:name="AA_DB_VERSION"
            android:value="1"/>

and this code into you application class

Configuration dbConfiguration = new Configuration.Builder(this)
                .setDatabaseName("MyDb.db")
                .addModelClass(User.class)
                .addModelClass(Topic.class)
                .addModelClass(Conference.class)
                .create();

ActiveAndroid.initialize(dbConfiguration);

derohimat avatar Jan 20 '17 05:01 derohimat

Hi @derohimat

Configuration dbConfiguration = new Configuration.Builder(this) --> in this line , Configuration which library. Not found application.

fatihbolat54 avatar Apr 20 '17 06:04 fatihbolat54

Disable Instant Run in AndroidStudio solved it

Samyssmile avatar Jul 27 '17 11:07 Samyssmile

you must add the model into AndroidMenifest.xml,just like this : <meta-data android:name="AA_MODELS" android:value="pakage.xxxModel, pakage.aaaModel,..."/> it worked for me !

wenzhihao123 avatar Sep 19 '17 09:09 wenzhihao123

check the Manifest, if your Application class is add <application android:name=".AppConfig" .....

my Class is: public class AppConfig extends Application {

@Override
public void onCreate() {
    super.onCreate();
    ActiveAndroid.initialize(this);
}

}

DavidAlejandroM avatar Feb 23 '18 14:02 DavidAlejandroM

please declare name in manifest.xml > name =".NameApplicaionClass" <application ... android:name=".YourApplicationNameHere" ...>

abolfazlsalmani avatar Apr 12 '18 20:04 abolfazlsalmani

android:value="aplicativo.oneplace.Entidades.USUARIO_CHAT_AMIGO_MENSAGEM,aplicativo.oneplace.Entidades.AMIGOS_USUARIO_SQLITE"

this is not working for me,

just this model is working = USUARIO_CHAT_AMIGO_MENSAGEM

this = AMIGOS_USUARIO_SQLITE not working... its the same package

lucazin avatar May 05 '18 15:05 lucazin

@lucazin android:value="aplicativo.oneplace.Entidades.USUARIO_CHAT_AMIGO_MENSAGEM,aplicativo.oneplace.Entidades.AMIGOS_USUARIO_SQLITE"

check that this line is in a single line, I think it does not work in several lines

DavidAlejandroM avatar May 08 '18 19:05 DavidAlejandroM

you should turn off InstanceRun .For me worked .

Senzosama avatar Jun 01 '18 11:06 Senzosama

Unable to create service io.uxtesting.uxtester.service.FloatingViewService: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String io.uxtesting.uxtester.model.TokenResult.getAppName()' on a null object reference

can anyone help me figure out this error

bhavu43 avatar Feb 18 '19 07:02 bhavu43

I had the same problem when I changed the location of the model. Double check in AndroidManifest.xml if the {modeLocation} is the same as the location in your directory.

up2marius avatar Jul 31 '19 13:07 up2marius