-1
我試圖讓我的數據庫可讀考慮,只有「categoria」是在選擇時被檢索,所以我開發這個代碼檢索數據:的Android數據庫SQLite的多哪來
plus = praia+ cafe+serv+rest+hot+muse+mon+escolas;
String dados[] = new String[plus];
//categoria is the name of the colum
String query = "categoria = ?";
for (i = 1; i < plus; i++) {
query = query+ " OR categoria = ?";
}
//if == 1 its active if == 0 its unactive;
if (praia == 1) {
dados[cont]= "Praias";
}
if (serv == 1) {
dados[cont]= "Servicos";
}
if (cafe == 1) {
dados[cont]= "Cafes";
}
if (rest == 1) {
dados[cont]= "Restaurantes";
}
if (hot == 1) {
dados[cont]= "Hoteis";
}
if (muse == 1) {
dados[cont]= "Museus";
}
if (mon == 1) {
dados[cont]= "Monumentos";
}
if (escolas == 1) {
dados[cont]= "Escolas";
}
String[] projections ={VianaContract.NewLocalInfo.Nome, VianaContract.NewLocalInfo.Categoria, VianaContract.NewLocalInfo.Latitude, VianaContract.NewLocalInfo.Longitude};
//error here
cursor = db.query(VianaContract.NewLocalInfo.Table_name, projections, query, dados, null, null, null);
這是logcat:
05-01 07:58:13.131 1435-1435/prosis.guiatour D/AndroidRuntime﹕ Shutting down VM
05-01 07:58:13.131 1435-1435/prosis.guiatour W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb3ac7ba8)
05-01 07:58:13.171 1435-1435/prosis.guiatour E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: prosis.guiatour, PID: 1435
java.lang.RuntimeException: Unable to start activity ComponentInfo{prosis.guiatour/prosis.guiatour.Lista}: java.lang.IllegalArgumentException: the bind value at index 3 is null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: the bind value at index 3 is null
at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:164)
at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
at prosis.guiatour.VianaDbHelper.getInfor(VianaDbHelper.java:123)
at prosis.guiatour.Lista.onCreate(Lista.java:49)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) 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:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)
你認爲是什麼導致錯誤?
有趣的事情,我有那部分在每一個連續增加,但我刪除它CUS我雖然是我不需要的代碼的一部分了:P – NobodyNemo
它工作感謝:D – NobodyNemo
很好聽!當你忘記爲什麼存在一段代碼並刪除它時,創建多少次錯誤是很有趣的。 – anthonycr