android - Error: Index 0 requested, with a size of 0. How can I resolve? -


this code:

package com.dev.paolo.sicinf;  import android.content.intent; import android.database.cursor; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.view; import android.widget.listview;  import java.math.biginteger;  import java.sql.sqlexception; import java.util.linkedlist; import java.util.list;   public class keysettings extends actionbaractivity {      public void generatekey(view view)     {         intent rsa = new intent (this, rsa.class);         startactivity(rsa);     }      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_key_settings);         listview listview = (listview)findviewbyid(r.id.list_keys);         list list = new linkedlist();         managerdb db = new managerdb(this);         cursor c= null;         string textd,texte,textn;         biginteger d,e,n;         try {             db.open();         } catch (sqlexception a) {             a.printstacktrace();         }         try         {             c = db.getkey(0);         }         catch (sqlexception a)         {             a.printstacktrace();         }         textd = c.getstring(2);         d = new biginteger(textd);         try         {             c = db.getkey(1);         }         catch (sqlexception a) {             a.printstacktrace();         }         texte = c.getstring(2);         e = new biginteger(texte);         try         {             c = db.getkey(2);         } catch (sqlexception a)         {             a.printstacktrace();         }         textn = c.getstring(2);         n = new biginteger(textn);         db.close();         list.add(new key("public key",e + " , " + n));         list.add(new key("private key",d + " , " + n));         customadapter adapter = new customadapter(this,r.layout.rowcustom,list);         listview.setadapter(adapter);     } } 

and error reported:

at android.app.activitythread.performlaunchactivity(activitythread.java:2307) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2365) @ android.app.activitythread.access$800(activitythread.java:164) @ android.app.activitythread$h.handlemessage(activitythread.java:1258) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:157) @ android.app.activitythread.main(activitythread.java:5350) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1265) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1081) @ dalvik.system.nativestart.main(native method) caused by: android.database.cursorindexoutofboundsexception: index 0 requested, size of 0 

i don't know how resolve problem. i've tried many guides available online haven't found solution.

this error occurring because db.getkey() trying access first item in empty list (i'm guessing list of keys in case). need either add database before point or add handling empty database.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -