My ORMlite service works for me. All CRUD operations are working fine. However, when I add a new field with a null value for my object, all this fails. I get null pointers and the application dies.
This is the field I added:
@DatabaseField( canBeNull = true ) private String newField;
If I drop my database and recreate it, everything will be fine. I would like to know why this is a simple circuit change? I think ahead, where the database is filled with data, and I do not want a new field with a zero value to break it, or can this be expected?
Here's the exception:
W/System.err(16955): java.sql.SQLException: Unknown field 'newField' from the Android sqlite cursor, not in:[desc, name, id] W/System.err(16955): at com.j256.ormlite.android.AndroidDatabaseResults.findColumn(AndroidDatabaseResults.java:97) W/System.err(16955): at com.j256.ormlite.field.FieldType.resultToJava(FieldType.java:793) W/System.err(16955): at com.j256.ormlite.stmt.mapped.BaseMappedQuery.mapRow(BaseMappedQuery.java:60) W/System.err(16955): at com.j256.ormlite.stmt.SelectIterator.getCurrent(SelectIterator.java:270)
Here is the exception that I get when I update an entity class to include the next new field.
@DatabaseField( canBeNull = true ) private String newField;
Now, seeing that if I delete the new field, the test file / application works fine, then this code breaks everything.
[2012-07-05 22:42:00 - WishListManager] Success! [2012-07-05 22:42:00 - WishListManagerTest] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 [2012-07-05 22:42:00 - WishListManagerTest] Collecting test information [2012-07-05 22:42:02 - WishListManagerTest] Sending test information to Eclipse [2012-07-05 22:42:02 - WishListManagerTest] Running tests... [2012-07-05 22:42:04 - WishListManagerTest] Test run failed: Instrumentation run failed due to 'java.lang.NullPointerException' [2012-07-05 22:42:04 - WishListManagerTest] Test run finished 07-05 21:42:02.084: I/TestRunner(16955): started: testAddDuplicateWishLists(com.tests.WishListServiceTest) 07-05 21:42:02.504: I/global(16955): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required. 07-05 21:42:02.524: I/global(16955): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required. 07-05 21:42:02.654: D/dalvikvm(16955): GC_FOR_MALLOC freed 4623 objects / 361912 bytes in 63ms 07-05 21:42:02.754: I/global(16955): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required. 07-05 21:42:02.764: I/global(16955): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required. 07-05 21:42:02.774: W/System.err(16955): java.sql.SQLException: Unknown field 'newField' from the Android sqlite cursor, not in:[desc, name, id] 07-05 21:42:02.784: W/System.err(16955): at com.j256.ormlite.android.AndroidDatabaseResults.findColumn(AndroidDatabaseResults.java:97) 07-05 21:42:02.784: W/System.err(16955): at com.j256.ormlite.field.FieldType.resultToJava(FieldType.java:793) 07-05 21:42:02.784: W/System.err(16955): at com.j256.ormlite.stmt.mapped.BaseMappedQuery.mapRow(BaseMappedQuery.java:60) 07-05 21:42:02.784: W/System.err(16955): at com.j256.ormlite.stmt.SelectIterator.getCurrent(SelectIterator.java:270) 07-05 21:42:02.784: W/System.err(16955): at com.j256.ormlite.stmt.SelectIterator.nextThrow(SelectIterator.java:161) 07-05 21:42:02.784: W/System.err(16955): at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:161) 07-05 21:42:02.784: W/System.err(16955): at com.j256.ormlite.stmt.StatementExecutor.queryForAll(StatementExecutor.java:113) 07-05 21:42:02.784: W/System.err(16955): at com.j256.ormlite.dao.BaseDaoImpl.queryForAll(BaseDaoImpl.java:237) 07-05 21:42:02.784: W/System.err(16955): at com.test.db.WishListService.getAllWishLists(WishListService.java:42) 07-05 21:42:02.784: W/System.err(16955): at com.test.WishListManagerActivity.setupListView(WishListManagerActivity.java:48) 07-05 21:42:02.784: W/System.err(16955): at com.test.WishListManagerActivity.onStart(WishListManagerActivity.java:44) 07-05 21:42:02.784: W/System.err(16955): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129) 07-05 21:42:02.784: W/System.err(16955): at android.app.Activity.performStart(Activity.java:3781) 07-05 21:42:02.784: W/System.err(16955): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636) 07-05 21:42:02.784: W/System.err(16955): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 07-05 21:42:02.794: W/System.err(16955): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 07-05 21:42:02.794: W/System.err(16955): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 07-05 21:42:02.794: W/System.err(16955): at android.os.Handler.dispatchMessage(Handler.java:99) 07-05 21:42:02.794: W/System.err(16955): at android.os.Looper.loop(Looper.java:123) 07-05 21:42:02.794: W/System.err(16955): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-05 21:42:02.794: W/System.err(16955): at java.lang.reflect.Method.invokeNative(Native Method) 07-05 21:42:02.794: W/System.err(16955): at java.lang.reflect.Method.invoke(Method.java:521) 07-05 21:42:02.794: W/System.err(16955): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-05 21:42:02.794: W/System.err(16955): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-05 21:42:02.794: W/System.err(16955): at dalvik.system.NativeStart.main(Native Method) 07-05 21:42:02.804: D/AndroidRuntime(16955): Shutting down VM 07-05 21:42:02.804: W/dalvikvm(16955): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 07-05 21:42:02.814: E/AndroidRuntime(16955): FATAL EXCEPTION: main 07-05 21:42:02.814: E/AndroidRuntime(16955): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.WishListManagerActivity}: java.lang.NullPointerException 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.os.Handler.dispatchMessage(Handler.java:99) 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.os.Looper.loop(Looper.java:123) 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-05 21:42:02.814: E/AndroidRuntime(16955): at java.lang.reflect.Method.invokeNative(Native Method) 07-05 21:42:02.814: E/AndroidRuntime(16955): at java.lang.reflect.Method.invoke(Method.java:521) 07-05 21:42:02.814: E/AndroidRuntime(16955): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-05 21:42:02.814: E/AndroidRuntime(16955): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-05 21:42:02.814: E/AndroidRuntime(16955): at dalvik.system.NativeStart.main(Native Method) 07-05 21:42:02.814: E/AndroidRuntime(16955): Caused by: java.lang.NullPointerException 07-05 21:42:02.814: E/AndroidRuntime(16955): at com.test.WishListManagerActivity.setupListView(WishListManagerActivity.java:51) 07-05 21:42:02.814: E/AndroidRuntime(16955): at com.test.WishListManagerActivity.onStart(WishListManagerActivity.java:44) 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129) 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.app.Activity.performStart(Activity.java:3781) 07-05 21:42:02.814: E/AndroidRuntime(16955): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636) 07-05 21:42:02.814: E/AndroidRuntime(16955): ... 11 more
source share