Skip to content
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

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

Open
sebastiandeutsch opened this issue Mar 21, 2016 · 45 comments

Comments

@sebastiandeutsch
Copy link

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

@sakkeerhussain
Copy link

I am also getting this error.

@sebastiandeutsch
Copy link
Author

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

@sebastiandeutsch
Copy link
Author

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

@sakkeerhussain
Copy link

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

@sakkeerhussain
Copy link

Hi @sebastiandeutsch

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

@svendvd
Copy link

svendvd commented Mar 22, 2016

Hi this is my simple workaround.
#462

@savicprvoslav
Copy link

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

Thanks.

@Christ9038
Copy link

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

@sakkeerhussain
Copy link

@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.

@Christ9038
Copy link

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

@sakkeerhussain
Copy link

@Christ9038 Great to here this from you.

Thanks,
Sakkeer Hussain

On 6 April 2016 at 19:48, Christ9038 notifications@github.com 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
#461 (comment)

@soygustavo
Copy link

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

@rohanraarora
Copy link

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?

@xahy
Copy link

xahy commented Apr 8, 2016

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

@strgen
Copy link

strgen commented Apr 8, 2016

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

@xahy
Copy link

xahy commented Apr 8, 2016

@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.

@strgen
Copy link

strgen commented Apr 8, 2016

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

@xushaojie
Copy link

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

@xushaojie
Copy link

@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 />

@xahy
Copy link

xahy commented Apr 8, 2016

@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 🤓

@xushaojie
Copy link

@xahy contains all models? check code again.

@sakkeerhussain
Copy link

@soygustavo like this

include full path to your model classes.

@rohanraarora
Copy link

@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.

@billyriantono
Copy link

@xushaojie thanks your solution is work ! 💃

@soygustavo
Copy link

@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" />

@ChathuraHettiarachchi
Copy link

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)

@zulqer
Copy link

zulqer commented Sep 14, 2016

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);
}

}

@derohimat
Copy link

thanks @xushaojie works for me

@pynixwang
Copy link

adding AA_MODELS to Manifest did solve this issue.

@Gustavol95
Copy link

@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

@pynixwang
Copy link

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

@pynixwang
Copy link

@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.

@PratikPagada
Copy link

PratikPagada commented Jan 18, 2017

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

@xushaojie
Copy link

@PratikPagada see my code.maybe useful.

@derohimat
Copy link

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);

@fatihbolat54
Copy link

Hi @derohimat

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

@Samyssmile
Copy link

Disable Instant Run in AndroidStudio solved it

@wenzhihao123
Copy link

wenzhihao123 commented Sep 19, 2017

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 !

@DavidAlejandroM
Copy link

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);
}

}

@abolfazlsalmani
Copy link

abolfazlsalmani commented Apr 12, 2018

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

@lucazin
Copy link

lucazin commented May 5, 2018

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

@DavidAlejandroM
Copy link

@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

@amir-nadi
Copy link

you should turn off InstanceRun .For me worked .

@bhavu43
Copy link

bhavu43 commented Feb 18, 2019

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

@up2marius
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests