我这里有一个SugarRecord
对象:
public class Options extends SugarRecord<Options> {
public boolean includeNumbers;
public boolean includeLowercase;
public boolean includeUppercase;
public int charCount;
public String includedChars;
public Options () {}
public static class Builder {
//builder thingys here
}
}
我只会将一个Options
对象保存到数据库中。我在名为Utility
的类中创建了一个方法来获取此对象:
public static Options getOptions () {
List<Options> optionsList = Options.listAll (Options.class);
if (optionsList.size () == 0) {
//return the default if there isn't an entry.
return new Options.Builder ().setCharCount (8)
.setIncludedChars ("")
.setIncludeLowercase (true)
.setIncludeNumbers (true)
.setIncludeUppercase (false).build ();
} else {
return optionsList.get (0);
}
}
现在,当我在活动中调用方法来读取对象时,会抛出NullPointerException
。这是调用堆栈:
Caused by: android.database.sqlite.SQLiteException: no such table: OPTIONS (code 1): , while compiling: SELECT * FROM OPTIONS
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1322)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1169)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1040)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1246)
at com.orm.SugarRecord.find(SugarRecord.java:208)
at com.orm.SugarRecord.listAll(SugarRecord.java:134)
at com.passwordgen.util.Utility.getOptions(Utility.java:94)
at com.passwordgen.OptionsActivity.onCreate(OptionsActivity.java:34)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
我真的不明白为什么会发生这种情况,因为我使用SugarORM保存了其他一些东西,而且它们都很好。请告诉我如何解决这个问题。
我的猜测是我的糖记录包含一些无法放入表中的东西,可能是布尔值?但这应该没问题,我很确定SQL数据库可以存储布尔值。