有些事情在我搜索了很多之后我没有找到真正的答案,问题是在android中创建超过1个sqlite数据库时,你是否可以调用特定数据库打开或不使用getWritabledatabase()
。然后我尝试了很多来调用这段代码:
SQLiteDatabase db;
SingleChatDataSource datasource;
datasource = new SingleChatDataSource(this);
datasource.open();
final String TABLE_CREATE =
"CREATE TABLE " + TABLE_TOURS + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_TITLE + " TEXT, " +
COLUMN_DESC + " TEXT, " +
COLUMN_IMAGE + " TEXT, " +
COLUMN_PRICE + " NUMERIC " +
")";
db.execSQL(TABLE_CREATE);
我收到此错误
05-25 23:27:00.068: E/AndroidRuntime(1200): FATAL EXCEPTION: main
05-25 23:27:00.068: E/AndroidRuntime(1200): Process: com.example.xmppchattest, PID:
05-25 23:27:00.068: E/AndroidRuntime(1200): java.lang.RuntimeException: Unable to
start service com.example.xmppchattest.WriterService@b2d4e430 with Intent {
cmp=com.example.xmppchattest/.WriterService }: java.lang.NullPointerException
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2719)
android.app.ActivityThread.access$2100(ActivityThread.java:135)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:136)
android.app.ActivityThread.main(ActivityThread.java:5017)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:515)
nullpointer异常是我在这里预期的最后一件事,有人可以帮帮我吗?
答案 0 :(得分:0)
db
未初始化。
有关如何正确初始化db
的信息,请参见SQLiteDatabase.openDatabase documentation。
(该页面上还有SQLiteDatabase.openOrCreateDatabase
一点点)