Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6113897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:54:42+00:00 2026-05-23T14:54:42+00:00

I have been stuck at one point from long time, i.e with the use

  • 0

I have been stuck at one point from long time, i.e with the use of

 SimpleCursorAdapter 

as it fails while returning the correct value. I have seen similar many post in SO itself, saying that I should add _id column in the cursor database query, rather I should do

 db.rawQuery(String,String)

My code in the onCreate(..) is

HospitalData = new Database(this);
HospitalData.open();
Cursor c = HospitalData.getAllRows_Patient_Db();
startManagingCursor(c);
c.moveToFirst();

//HERE SOME LOOP IS NEEDED FOR TRAVERSING AND PUTTING IN THE LISTVIEW
while(c.isAfterLast() == false)
{
    String[] columns = new String[] { c.getString(1), c.getString(2) };
    int[] to = new int[] { R.id.room_number_db, R.id.pt_initial_db };
    adapter = new SimpleCursorAdapter(this,R.layout.patient_db, c,columns,to);
    c.moveToNext();
}
setListAdapter(adapter);

And previously my database accessing code was as follows

 public Cursor getAllRows_Patient_Db() 
{               
    return db.query(DATABASE_PATIENT_TABLE, new String[] {KEY_ROWID, KEY_ROOM_NUMBER,                             
                                                        KEY_PATIENT_INITIAL
            }, 
            null, 
            null, 
            null, 
            null, 
            null);
}

where KEY_ROWID is defined as follows

public static final String KEY_ROWID = "_id";

And the error with this is

07-04 22:10:23.301: ERROR/AndroidRuntime(16795): Caused by: java.lang.IllegalArgumentException: column '90' does not exist
07-04 22:10:23.301: ERROR/AndroidRuntime(16795):     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
07-04 22:10:23.301: ERROR/AndroidRuntime(16795):     at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:312)

Here column 90 is not the column id but according to my database is the data stored in cursor.getString(1), but I think here it is trying to search cursor.getString(0) which is the row id.

Later I changed my code as follows

public Cursor getAllRows_Patient_Db() 
{
  String db_sel = "SELECT id as _id, KEY_ROOM_NUMBER" +
    ",KEY_PATIENT_INITIAL FROM DATABASE_PATIENT_TABLE";

    return db.rawQuery(db_sel,null);
}

But still I am getting error, this time error is different

07-04 21:36:12.510: ERROR/global(9861): Deprecated Thread methods are not supported.

 07-04 21:36:12.950: ERROR/AndroidRuntime(9861): FATAL EXCEPTION: main
 07-04 21:36:12.950: ERROR/AndroidRuntime(9861): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pro/com.pro.CopyOfFirstScreen}: android.database.sqlite.SQLiteException: no such table: DATABASE_PATIENT_TABLE: , while compiling: SELECT id as _id, KEY_ROOM_NUMBER,KEY_PATIENT_INITIAL FROM DATABASE_PATIENT_TABLE

 07-04 21:36:12.950: ERROR/AndroidRuntime(9861): Caused by: android.database.sqlite.SQLiteException: no such table: DATABASE_PATIENT_TABLE: , while compiling: SELECT id as _id, KEY_ROOM_NUMBER,KEY_PATIENT_INITIAL FROM DATABASE_PATIENT_TABLE

I am stuck with it from very long time, please help!!

EDIT : Okay now with you guys help my query statement is correct and thanks for that, I am sorry I am not good in understanding the syntax for database query but I am trying to learn

The working query after changes is

String db_sel = "SELECT _id as _id, room_number" +",patient_initial FROM " + DATABASE_PATIENT_TABLE;

Actually I had to change the declared String with the key values

public static final String KEY_ROWID = "_id";
public static final String KEY_ROOM_NUMBER = "room_number";
public static final String KEY_PATIENT_INITIAL = "patient_initial";

But now I see another problem that is not from the query statement but the way I am accessing or using the simplecursorAdapter

DB Table

As you can see that my table has 2 rows and 3 columns, Now I want to fetch the data from column 2 and column 3 and put it in my listview.
But after the fix from the query I am getting another error

Originally it was

   String[] columns = new String[] {c.getString(1), c.getString(2) };
        int[] to = new int[] {  R.id.room_number_db, R.id.pt_initial_db };
     adapter = new SimpleCursorAdapter(this,R.layout.patient_db, c,columns,to);
     c.moveToNext();
    setListAdapter(adapter);

And the error was

  07-05 21:32:29.228: ERROR/AndroidRuntime(1505): Caused by: java.lang.IllegalArgumentException: column '90' does not exist
  07-05 21:32:29.228: ERROR/AndroidRuntime(1505):     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
  07-05 21:32:29.228: ERROR/AndroidRuntime(1505):     at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:312)

android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:312)

As you can see it is trying to access the data of first column inspite of accessing the row

After that I made changes in my code

     int x = 0;         
     String[] columns = new String[] { c.getString(0),c.getString(1), c.getString(2) };
        int[] to = new int[] { x, R.id.room_number_db, R.id.pt_initial_db };
     adapter = new SimpleCursorAdapter(this,R.layout.patient_db, c,columns,to);
     c.moveToNext();
    setListAdapter(adapter); 

This was only a guess in order to find out how differently SimpleCursorAdapter works compared to a normal cursor and the error I get is

 07-05 21:34:47.947: ERROR/AndroidRuntime(1966): Caused by: java.lang.IllegalArgumentException: column '1' does not exist
 07-05 21:34:47.947: ERROR/AndroidRuntime(1966):     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)

I know this question is becoming too long 🙁 do u suggest me to remove some code from here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:54:43+00:00Added an answer on May 23, 2026 at 2:54 pm

    The problem is fixed, the main thing is that I should make sure I always query for the _id with each query to the database, but if I do it with cursor.getString(someIndex) then this gets misleaded as the adapter in my case is taking the content of first column as the rowid and is trying to search the row.

    Nether doing rawQuery(),or using “Select _id as _id” stuffs are mandatory. these things are sometime misleading as I felt.

    So keeping things simple below is the code.
    Database code

     public Cursor getAllRows_Patient_Db() 
    {               
        return db.query(DATABASE_PATIENT_TABLE, new String[] {
                KEY_ROWID, 
                KEY_ROOM_NUMBER,
                KEY_PATIENT_INITIAL
                }, 
                null, 
                null, 
                null, 
                null, 
                null);
    }
    

    Activity Code

        HospitalData = new Database(this);
        HospitalData.open();
        Cursor c = HospitalData.getAllRows_Patient_Db();
    
    
        startManagingCursor(c);
    
        String[] columns = new String[] {HospitalData.KEY_ROOM_NUMBER,HospitalData.KEY_PATIENT_INITIAL };
         int[] to = new int[] {  R.id.room_number_db, R.id.pt_initial_db };
         adapter = new SimpleCursorAdapter(this,R.layout.patient_db, c,columns,to);
         c.moveToNext();
         setListAdapter(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a question, been stuck for a while, i dont know how can
I have been stuck on this for days, and was wondering if anyone had
Hope to get solution to this problem. I have been stuck on it since
I've been stuck with this for weeks now and have no idea where I'm
I've been stuck on a little unix command line problem. I have a website
I have been trying to make an init script using start-stop-daemon. I am stuck
The rails books and web pages I've been following have all stuck to very
I have been doing a phonegap app for android but am stuck on the
I've been stuck with this problem for over a week now. Hopefully some one
I've been getting stuck into some linq queries for the first time today and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.