Ho inserito questa select, se la colonna stipendio contiene dati tutto funziona, se faccio un wipe e riprovo, senza dati nella relativa colonna, l'app va in crash, come posso risolvere?
Cursor stipcursor = dataBase.rawQuery("SELECT (stipendio) AS stip FROM "+DbHelper.STIPENDI+" WHERE MESI = 'Gennaio' and ANNI = "+anno+"", null);
int colIndexstip = stipcursor.getColumnIndex("stip");
if (colIndexstip == -1)
return;
else
stipcursor.moveToFirst();
double stip = stipcursor.getDouble(colIndexstip);
System.out.println("Stipendio "+stip);
questo invece è il log di errore a db vuoto
05-02 19:39:18.524: E/AndroidRuntime(26089): FATAL EXCEPTION: main
05-02 19:39:18.524: E/AndroidRuntime(26089): java.lang.RuntimeException: Unable to resume activity {turni.db.tab/com.turniDB.TurniDB}: java.lang.RuntimeException: Unable to resume activity {turni.db.tab/mesi.Gennaio}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2444)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.os.Looper.loop(Looper.java:137)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-02 19:39:18.524: E/AndroidRuntime(26089): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 19:39:18.524: E/AndroidRuntime(26089): at java.lang.reflect.Method.invoke(Method.java:511)
05-02 19:39:18.524: E/AndroidRuntime(26089): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-02 19:39:18.524: E/AndroidRuntime(26089): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-02 19:39:18.524: E/AndroidRuntime(26089): at dalvik.system.NativeStart.main(Native Method)
05-02 19:39:18.524: E/AndroidRuntime(26089): Caused by: java.lang.RuntimeException: Unable to resume activity {turni.db.tab/mesi.Gennaio}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2444)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:178)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:523)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityGroup.onResume(ActivityGroup.java:61)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.Activity.performResume(Activity.java:4539)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
05-02 19:39:18.524: E/AndroidRuntime(26089): ... 12 more
05-02 19:39:18.524: E/AndroidRuntime(26089): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:400)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.database.AbstractWindowedCursor.getDouble(AbstractWindowedCursor.java:86)
05-02 19:39:18.524: E/AndroidRuntime(26089): at mesi.Gennaio.displayData(Gennaio.java:340)
05-02 19:39:18.524: E/AndroidRuntime(26089): at mesi.Gennaio.onResume(Gennaio.java:191)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.Activity.performResume(Activity.java:4539)
05-02 19:39:18.524: E/AndroidRuntime(26089): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
05-02 19:39:18.524: E/AndroidRuntime(26089): ... 18 more