java.lang.IllegalStateException

tip

You have an empty cursor. Check your query if it is not expected, or handle empty cursor with `if(cursor.getCount() > 0) ...`

tip

You need to make sure that there is a data in the cursor. Check that moveToFirst() return true.


rprp
tip

When you get a Cursor returned from the database you should do an moveToFirst(); before trying to get data from it.

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • size zero - 必应
    via by Unknown author,
  • Printing database to string not working
    via Stack Overflow by Soundwave
    ,
    • java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293) at android.view.View.performClick(View.java:5226) at android.view.View$PerformClick.run(View.java:21266) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:168) at android.app.ActivityThread.main(ActivityThread.java:5845) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) ... 9 more 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.pos.example.LoginActivity.checkLogin(LoginActivity.java:69) at com.pos.example.LoginActivity.onClick(LoginActivity.java:40) at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:5226) at android.view.View$PerformClick.run(View.java:21266) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:168) at android.app.ActivityThread.main(ActivityThread.java:5845) at java.lang.reflect.Method.invoke(Native Method)

    Users with the same issue

    AkshayAkshay
    1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    faisalmohd83faisalmohd83
    2 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    51 more bugmates