i'm getting error whenEver i try to get data from my db using this function(i'm using kotlin with android studio)

user9483334
fun readChore(id:Int):Chore{
     val db:SQLiteDatabase=writableDatabase

    val cursor:Cursor=db.query(TABLE_NAME,arrayOf(KEY_ID,KEY_CHORE_ASSIGNED_TO, KEY_CHORE_ASSIGNED_BY,
               KEY_CHORE_ASSINED_TIME),KEY_ID+"=?",arrayOf(id.toString()),
               null,null,null,null)

    Log.d("position",cursor.position.toString())

    cursor.moveToFirst()

    val chore=Chore(
            cursor.getString(cursor.getColumnIndex(KEY_CHORE_NAME)),
            cursor.getString(cursor.getColumnIndex(KEY_CHORE_ASSIGNED_TO)),
            cursor.getString(cursor.getColumnIndex(KEY_CHORE_ASSIGNED_BY)),
            cursor.getLong(cursor.getColumnIndex(KEY_CHORE_ASSINED_TIME))
    )

    return chore
}

But all i'm getting is an error__saying ..."Failed to read row 0, column -1 from a CursorWindow which has 1 rows, 4 columns."

leonardkraemer

You have to add KEY_CHORE_NAME to the selected rows

val cursor:Cursor=db.query(TABLE_NAME,arrayOf(KEY_ID, KEY_CHORE_NAME ,KEY_CHORE_ASSIGNED_TO, KEY_CHORE_ASSIGNED_BY,
           KEY_CHORE_ASSINED_TIME),KEY_ID+"=?",arrayOf(id.toString()),
           null,null,null,null)

For future debugging you can use Databaseutils.dumpCursor() to see the contents of your cursor, which is otherwise hard to see.

Also don't forget to close the cursor cursor.close() before the return statement.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Getting error when I'm trying to get data from 3 table using sql INNER JOIN query

I'm trying to use OPENPYXL, I get this TYPE ERROR whenever i try to create an excel file

Android studio random I'm getting an error

How can I get JSON data from a URL using PHP? I'm getting authentication failure

I try getting data from eBay from sold and auction items using webscraping but for some reason i get a NoneType error

I'm beginner and try to re-write java code to Kotlin, using canvas, try write a circle. But as a result I get only blank screen on my Device

I'm trying to get mlab data into console using node.js but getting this error

I'm getting data from my sql DB and How to remove Backslashes from JSON data?

i'm getting an error while using findViewById()

When I'm using RequestDispatcher and using forward to send my my request and response to a new servlet I'm getting error

Getting an error in the Email textbox whenever i try to SignUp using a Site for testing

Kotlin Android studio I'm getting an unresolved reference

In laravel i'm getting the following error while add data to db

I'm getting error during updating my current android studio 3.3 to latest

Trying to save values to an Access DB, but I'm getting an error when I try ExecuteNonQuery

my error object is undefined when i`m using rtk query with try/catch

When I'm using URLEncoder for Http GET Request I'm getting proper URL but when I push that code to live or on server I'm getting error

How do I get my new constructor to work? I'm using Javascript in Visual Studio Code

I'm trying to create a SQL query using an inner join but I'm getting a syntax error for my first inner join statement

There is an interesting problem. I'm using Laravel 8 and I'm getting this error from the passport: install command, I couldn't solve it

I'm getting 'AttributeError' whenever I try to edit any entry through forms in Django

I'm getting this type error when I try to label my plot

At the time upload files from my website I'm getting this error

I'm getting an error from the implementation of my region of interest

On line 138 of my code I keep getting an "expected a ';'" error (code E0065). I'm using Visual Studio 2019 Community Edition

I'm fetching dynamic data from my nodejs to reactjs but I get an error saying "POST IS NOT DEFINED"

Android Studio- I'm trying search users from firebase database but getting error

My code runs well with arrow function and using { }, but when { } are removed i'm getting syntax error

I want to save data in DB using fill but I get an error

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive