类型 Character 无法直接存储到数据库
Character 类型不是原始支持的类型, 转换为 String 类型存储到数据库;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
private String firstCharString = "~"; @Transient private Character firstChar = '~';//放弃存储 public void setFirstCharString(String firstCharString) { // 在 set String 时, 给 Character 赋值 if (firstCharString.length() > 0) { firstChar = firstCharString.charAt(0); } else { firstChar = BTConfig.specialChar; } this.firstCharString = firstCharString; } public void setFirstChar(Character firstChar) { firstCharString = firstChar + ""; this.firstChar = firstChar; } |
构造方法发生改变
1 2 3 4 |
Error:Execution failed for task ':../libs:lib:greendao'. > Constructor (see ....) has been changed after generation. Please either mark it with @Keep annotation instead of @Generated to keep it untouched, or use @Generated (without hash) to allow to replace it. |
删掉自动生成的构造方法, 然后再次编译重新生成构造方法
NullPointerException getDatabaseLocked
DevOpenHelper(Context context, String name, CursorFactory factory) 构造参数传入的 Context 对象为 null, 使用其它 Context 作为参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
java.lang.NullPointerException at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224) at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164) at org.greenrobot.greendao.database.DatabaseOpenHelper.getWritableDb(DatabaseOpenHelper.java:59) ...... ...... at android.view.View.performClick(View.java:4438) at android.view.View$PerformClick.run(View.java:18422) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613) at dalvik.system.NativeStart.main(Native Method) |
0 Comments