Sebastian
Sebastian

Reputation: 417

Listview Click Error

When I click on a list Item in listview. The app crashes and I get this error. How can I solve it or why is the error occurring?

10-18 13:35:03.029 11283-11283/com.example.sebastian.dblist E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sebastian.dblist, PID: 11283
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sebastian.dblist/com.example.sebastian.dblist.DisplayContact}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
  at android.app.ActivityThread.-wrap11(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
  at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
  at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
  at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
  at com.example.sebastian.dblist.DisplayContact.onCreate(DisplayContact.java:63)
  at android.app.Activity.performCreate(Activity.java:6237)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:148) 
  at android.app.ActivityThread.main(ActivityThread.java:5417) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Upvotes: 0

Views: 78

Answers (2)

Qian Sijianhao
Qian Sijianhao

Reputation: 564

You are reading some data from database when click is performed on your listview.But there is no proper data which means cusor.next() return false. But you force to read by this Cusor and it finally result in an IndexOutOfBoundsException.

Upvotes: 0

Ganesh Pokale
Ganesh Pokale

Reputation: 1594

this is your SQLite database exception

Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0

I think you are trying to get data from empty table

Upvotes: 2

Related Questions