Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempt to invoke virtual method 'java.lang.Class java.lang.reflect.Field.getType()' on a null object reference

I'm using activeandroid in my android app.

Everything works fine running a debug build while developing. After creating a release build of my project the app is now crashing. This happens on a Nexus5 with Android 5.0 aswell as on a Nexus 7 with Android 4.4.2.

Here's the source code if you need to take a look!
https://github.com/MetalMatze/Krautreporter

Thanks!

java.lang.RuntimeException: Unable to create application com.activeandroid.app.Application: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.reflect.Field.getType()' on a null object reference
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4521)
at android.app.ActivityThread.access$1500(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.reflect.Field.getType()' on a null object reference
at com.activeandroid.e.f.c(Unknown Source)
at com.activeandroid.e.f.c(Unknown Source)
at com.activeandroid.f.c(Unknown Source)
at com.activeandroid.f.onCreate(Unknown Source)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.activeandroid.b.b(Unknown Source)
at com.activeandroid.b.a(Unknown Source)
at com.activeandroid.a.a(Unknown Source)
at com.activeandroid.a.a(Unknown Source)
at com.activeandroid.a.a(Unknown Source)
at com.activeandroid.app.Application.onCreate(Unknown Source)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518)
... 9 more
like image 987
Matthias Loibl Avatar asked Dec 10 '14 19:12

Matthias Loibl


1 Answers

You use reflection to find a field by its name. Your release build gets minified by Proguard/R8 which renames fields to something short and obscure. You need to add a rule to Proguard/R8 to keep the field names you access using reflection.

There's already an answer for how to keep fields in all or certain classes here: https://stackoverflow.com/a/23365501/2444099

like image 112
Eugen Pechanec Avatar answered Oct 17 '22 12:10

Eugen Pechanec