Issue
I have published my app to PlayStore, in debug all was going well, in the new version i've added two new tables, the insert method and other stuff and changed the db version.
The issue is that once i've downloaded the PlayStore version of the APP the app suddenly crashed with the following error:
Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
it.gabtamagnini.visualposmobile.database.DataBaseHandler.insertMC (DataBaseHandler.java:59)
it.gabtamagnini.visualposmobile.TastiActivity$1.onCompleted (TastiActivity.java:32)
it.gabtamagnini.visualposmobile.TastiActivity$1.onCompleted (TastiActivity.java:2)
com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked (SimpleFuture.java:10)
com.koushikdutta.async.future.SimpleFuture.setComplete (SimpleFuture.java:22)
Logcat:
java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
at y5.a.N(:216)
at it.gabtamagnini.visualposmobile.TastiActivity.Q(:464)
at it.gabtamagnini.visualposmobile.TastiActivity.o(Unknown Source:0)
at v5.r0.a(Unknown Source:4)
at b5.h.p(:107)
at b5.h.v(:141)
at b5.h.w(:128)
at m5.l$a.run(:246)
at z4.g$l.run(:60)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7860)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
insertMC is one of new methods to insert the data in the new created tables, so i think that in release version of the app the new tables were not created so that's the reason why the app crash in that point.
The issue is that even after uninstalling and installing the app again (which should forced the onCreate of DBHandler) the issue still persists...
Here is the method:
public void insertMC(Menu menu) {
database = this.getWritableDatabase();
ContentValues valuesMenu = new ContentValues();
valuesMenu.put("DESCRIPTION", menu.desc);
valuesMenu.put("OPZIONALE", menu.opzionale);
valuesMenu.put("LIMITE", menu.limite);
valuesMenu.put("PLU", menu.plu);
long id = database.insertWithOnConflict(TABLE_MC, null, valuesMenu, SQLiteDatabase.CONFLICT_REPLACE);
for (Menu.Prodotti prodotto :
menu.prodotti) {
ContentValues valuesProdotto = new ContentValues();
valuesProdotto.put("DESCRIPTION", prodotto.desc);
valuesProdotto.put("CODICE", prodotto.codice);
valuesProdotto.put("PREZZO", prodotto.prezzo);
valuesProdotto.put("QTA", prodotto.qta);
valuesProdotto.put("MENU", id);
valuesProdotto.put("JUMP", prodotto.jump);
database.insertWithOnConflict(TABLE_MC_PRODOTTI, null, valuesProdotto, SQLiteDatabase.CONFLICT_REPLACE);
}
}
What should be the issue? if that's DB table creation problem, how can i force it in release? Else how can i run a debug of a release version of the app?
release attributes:
release {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
My proguard:
-keep class org.sqlite.** { *; }
-keep class org.sqlite.database.** { *; }
-keep class it.gabtamagnini.visualposmobile.models.Menu
Solution
Thank to @UsamaAltaf i got that the issue was with the minifyEnabled property, so by investigating i've ended up that the issue was the minified model class Menu
The solution was to add it to proguard, so to make it work i've added this lines to proguard:
-keep class it.gabtamagnini.visualposmobile.models.Menu
-keepclassmembers class it.gabtamagnini.visualposmobile.models.Menu { *; }
It wasn't necessary to add -keep
on sqlite
class.
Answered By - NiceToMytyuk