SimpleCursorAdapter exception; column '_id' does not exist

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

SimpleCursorAdapter exception; column '_id' does not exist

Postby sazabo » Thu Nov 20, 2008 5:05 pm

Hello all, I have a problem that I cannot find with an exception coming from inside the SimpleCursorAdapter.

thanks for the help,
"I'm stumped" :(
Jeff

Preamble: database in and out is working; cursor is returning correct columns, this code is based on Notepad.
I am attempting to display one column from a table to a textView.

I have been trying everything, but still the same error. .
Any thoughts??
thanks

Code:
java.lang.IllegalArgumentException: column '_id' does not exist

***
import static android.provider.BaseColumns._ID;
...


private static final String[] PROJECTION = new String[] {
_ID, //BASECOLUMNS
//Meds.sSOURCE,
Meds.sPRODUCT, };



SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.mphrlist_item,
cursor,
new String[] { "PRODUCT" }, //from

new int[] { android.R.id.text1 }); //to


OUTPUT FROM THE LOG TRACE
11-19 18:10:29.457: ERROR/MPhrList(194): OnCreate
11-19 18:10:29.887: ERROR/MPhrList(194): OnCreate cursor.getCount = 4
11-19 18:10:29.897: ERROR/MPhrList(194): OnCreate cursor.getColumnName0 = _ID
11-19 18:10:29.897: ERROR/MPhrList(194): OnCreate cursor.getColumnName1 = PRODUCT
11-19 18:10:39.296: WARN/ActivityManager(50): Launch timeout has expired, giving up wake lock!
- Show quoted text -

Manifest.xml
<activity android:name=".MPhrList"
android:label="@string/title_mphrs_list"
>
<!-- view all meds-->
<intent-filter android:label="@string/new_med_label">
<action android:name="android.intent.action.INSERT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/vnd.csi.meds" />
</intent-filter>

</activity>

mphrlist.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:singleLine="true"
/>
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

Top

Postby MrSnowflake » Thu Nov 20, 2008 5:53 pm

Your database table should have a field called "_id"!
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

table does have _id column

Postby sazabo » Thu Nov 20, 2008 6:01 pm

thanks for reply, sorry I forgot to post that code. I was wondering if it has something to do with the xml files??

note BaseColumns._ID = "_id" lowercase
import static android.provider.BaseColumns._ID;
...


public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + MEDS_TABLE_NAME + " ("
+ _ID + " INTEGER PRIMARY KEY autoincrement,"
+ Meds.sMEDS_FK + " INTEGER ,"
+ Meds.sSTATUS + " TEXT,"
+ Meds.sSOURCE + " TEXT,"
+ Meds.sPRODUCT + " TEXT,"
+ Meds.sDIRECTIONS + " TEXT,"
+ Meds.sFULLFILLHISTORY + " TEXT,"
+ Meds.sCREATION_DATE + " TEXT,"
+ Meds.sMODIFIED_DATE + " TEXT"
+ ");");
}
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

Postby MrSnowflake » Thu Nov 20, 2008 6:12 pm

Yeah, the could would have been a lot more usefull :). Is it working now?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

still not working

Postby sazabo » Thu Nov 20, 2008 6:17 pm

I had the column _id in before. I am also printing it out in my log via the cursor??? I spoke to someone a google and he said that they case check but the case. Ive tried it both ways upper and lower case. both give same results. That is why I am thinking it is something else other than the cursor??

it's twisted, or I'm twisted

thanks

JEff
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

Postby MrSnowflake » Thu Nov 20, 2008 6:20 pm

You are probably having one of those stupid little mistakes going on :).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby BenS » Fri Feb 06, 2009 8:48 pm

You have to fetch the Column _id for your cursor. It's not enough to have this in your table, but every result must have it, to iterate over it.

Hope this helps you.

Regards,

BenS
BenS
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Feb 06, 2009 8:44 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests