vendredi 1 mai 2015

Android Database Sqlite Retrieving data with multiple where's

So I'm trying to make my database readable having in consideration that only the "categoria" that where selected are retrieved, so i developed this code:

        plus = praia+ cafe+serv+rest+hot+muse+mon+escolas;
    String dados[] = new String[plus];
//categoria is the name of the colum
    String querry = "categoria = ?";
    for(i=1; i<plus;i++){
        querry = querry+ " 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,querry, dados, null, null,null);

And this is the 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)

What do you think is causing the error ?

Aucun commentaire:

Enregistrer un commentaire