after bootup,crashing

前端 未结 5 1607
轮回少年
轮回少年 2021-01-16 02:40

My application is using a bootup service.In the service i have to get values from a database,but the app is crashing as it tries getting the values...

The logcat err

相关标签:
5条回答
  • 2021-01-16 03:37

    The error says that you are trying to receive the string from the column with index -1 which is WRONG. Columns are enumerated starting from 0. As google's doc says about Cursor.getColumnIndex(String name), it returns -1 if the column with "name" name doesn't exist. Check the line 69 of your MyService.java file:

    String num1 = cursor2.getString(cursor2.getColumnIndex("secure"));
    

    I think there is no "secure" column in your database. Verify your database.

    0 讨论(0)
  • 2021-01-16 03:38

    Where is the database located? And are you sure you have your permissions set? Also, could you post the code to your MyService Class?

    0 讨论(0)
  • 2021-01-16 03:41

    When you Create Cursor from the Database you have to first check for both (cursor != null && cursor.moveToFirst()). In your case if there is no any data available then it will create a problem.

    so before you use Cursor add the condition

    if(c != null && c.moveToFirst()) {
    //write your code here
    } 
    

    java.lang.IllegalStateException: get field slot from row 0 col -1 failed

    Normally this error you will get if you are trying to read a column value from the cursor but that column is not exists in the cursor.

    0 讨论(0)
  • 2021-01-16 03:43

    From the error it seems that you are fetching some content from the Database in the Cursor. But fetching the content from the Cursor you need to point the Cursor to the first row that your cursor contains. So you need to apply cursor.moveToFirst(); to get it working, if this is the case. Else you should post the full source or the code where you feel its crashing.

    0 讨论(0)
  • 2021-01-16 03:44

    I found the answer for this myself...

    the error,rather say;my mistake in coding was that i was supposed to use moveToNext() instead of isAfterLast()

    0 讨论(0)
提交回复
热议问题