$100 via Paypal to help me fix a bug, Exception: column '_id

Offer / request Android-related Jobs.
Search for a team or team-members.

$100 via Paypal to help me fix a bug, Exception: column '_id

Postby sazabo » Mon Nov 24, 2008 6:52 pm

Hello All,

I have a bug that I cannot find and I need another set of eyes. I will pay $100.00 for the answer/fix to this bug. Payment will be made via PayPal. This will also be an opportunity for more work in the future. This is a great site that gives great answers, I just want to pay to get it quicker. Please contact me if you are interested so I do not have multiple people working on the problem. I will only pay for one correct answer.

Check out my company site and my linkedin profile. I am legit and have been in business for a long time.
www.comsi.com
http://www.linkedin.com/in/jeffreyleebrandt

thanks,
Jeff

I am trying to use a ContentProvider and getting errors; The query with throws an exception. IllegalArgumentException: column '_id' does not exist

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

Insert is working:

long rowId = db.insert(MEDS_TABLE_NAME, Meds.MED, values);
Log.e(TAG, "aft insert rowId = " + rowId);
LOG --11-21 08:32:30.983: ERROR/MPhrProvider(195): aft insert rowId = 10

if (rowId > 0) {
Uri medUri = ContentUris.withAppendedId(MPhrDef.Meds.CONTENT_URI, rowId); // append rowid at end of givin uri

getContext().getContentResolver().notifyChange(medUri, null);
return medUri;

SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, null);
Log.e(TAG, "OnCreate cursor.getColumnName0 = " + c.getColumnName(0));
Log.e(TAG, "OnCreate cursor.getColumnName1 = " + c.getColumnName(1));

LogCat
11-24 09:29:23.199: ERROR/MPhrList(212): OnCreate cursor.getColumnName0 = _ID
11-24 09:29:25.347: ERROR/MPhrList(212): OnCreate cursor.getColumnName1 = SOURCE
________________________________________________________________________
Content Provider

public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + MEDS_TABLE_NAME + " ("
+ Meds._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"
+ ");");
Log.w(TAG, "onCreate");
}

public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

// String sTable = qb.getTables();

switch (sUriMatcher.match(uri)) {
case MEDS: // get all meds in db
qb.setTables(MEDS_TABLE_NAME);
qb.setProjectionMap(sMedsProjectionMap);
break;

case MED_ID: //get single med
qb.setTables(MEDS_TABLE_NAME);
qb.setProjectionMap(sMedsProjectionMap);
qb.appendWhere(Meds._ID + "=" + uri.getPathSegments().get(1));
break;

default:
throw new IllegalArgumentException("Unknown URI " + uri);
}

// If no sort order is specified use the default
String orderBy;
if (TextUtils.isEmpty(sortOrder)) {
orderBy = MPhrDef.Meds.DEFAULT_SORT_ORDER;
} else {
orderBy = sortOrder;
}

// Get the database and run the query
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, null);
Log.e(TAG, "OnCreate cursor.getColumnName0 = " + c.getColumnName(0));
Log.e(TAG, "OnCreate cursor.getColumnName1 = " + c.getColumnName(1));
/*
String[] p = {"_id", "SOURCE", "PRODUCT"};
String st = qb.buildQuery(p, selection, selectionArgs, null, null, orderBy, null);
st = ("select * from "+ MEDS_TABLE_NAME + "where(_id=3);");
Cursor cc =db.rawQuery(st, null);
*/
// Tell the cursor what uri to watch, so it knows when its source data changes
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}




_________________________________________________________________
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
Log.e(TAG, "OnCreate");
setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);

Intent intent = getIntent();
if (intent.getData() == null) {
intent.setData(Meds.CONTENT_URI);
}

// Inform the list we provide context menus for items
getListView().setOnCreateContextMenuListener(this);

setContentView(R.layout.medlist);

// Perform a managed query. The Activity will handle closing and re-querying the cursor
// when needed.

Uri uri = getIntent().getData();
Cursor cursor = managedQuery(uri, PROJECTION, null, null, Meds.DEFAULT_SORT_ORDER);
//Cursor cursor = managedQuery(Meds.CONTENT_URI, PROJECTION, null, null, null);

Log.e(TAG, "OnCreate cursor.getCount = " + cursor.getCount());
//Log.e(TAG, "OnCreate cursor.getInt(0) = " + cursor.getInt(0));
//cursor.copyStringToBuffer(1, new android.database.CharArrayBuffer(5));
Log.e(TAG, "OnCreate cursor.getColumnName0 = " + cursor.getColumnName(0));
Log.e(TAG, "OnCreate cursor.getColumnName1 = " + cursor.getColumnName(1));

/* Used to map meds entries from the database to views
*/
try{
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.mphrlist_item,
cursor,
new String[] { "PRODUCT" }, //from
new int[] { android.R.id.list }); //to
setListAdapter(adapter);
} catch (Exception e) {
Log.e(TAG, "Exception caught Simple.. ", e);


Exception Caught
11-24 09:29:50.237: ERROR/MPhrList(212): Exception caught Simple..
11-24 09:29:50.237: ERROR/MPhrList(212): java.lang.IllegalArgumentException: column '_id' does not exist
11-24 09:29:50.237: ERROR/MPhrList(212): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:310)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.CursorAdapter.init(CursorAdapter.java:111)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.CursorAdapter.<init>(CursorAdapter.java:90)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:46)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:84)
11-24 09:29:50.237: ERROR/MPhrList(212): at com.csi.android.mPHR.MPhrList.onCreate(MPhrList.java:102)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2103)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2156)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

Top

Postby MrSnowflake » Mon Nov 24, 2008 7:13 pm

Give us the sql of the table.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby sazabo » Mon Nov 24, 2008 7:45 pm

Snow, is this what you needed? send me your email and I will send the code. My email is jlbcsi@gmail.com The query code is in the original post via a querybuilder.
Jeff

public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + MEDS_TABLE_NAME + " ("
+ Meds._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"
+ ");");
Log.w(TAG, "onCreate");
}
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

Postby MrSnowflake » Mon Nov 24, 2008 7:58 pm

Sorry, I missed in your post, it was there already.

But you should post the Meds class.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

MEDS

Postby sazabo » Mon Nov 24, 2008 8:09 pm

package com.csi.android.mPHR;

import android.net.Uri;
import android.provider.BaseColumns;

//import static android.provider.BaseColumns._ID; NOTE THAT THIS IS COMMENTED OUT

/**
* Convenience definitions for MPhrProvider
*/
public final class MPhrDef {
public static final String AUTHORITY = "com.csi.android.mPHR";

// This class cannot be instantiated
private MPhrDef() {}

/**
* Meds table

public static final class Meds implements BaseColumns {
// This class cannot be instantiated
private Meds() {}

/**
* The content:// style URL for this table (tablename = meds)
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/meds");

/**
* The MIME type of {@link #CONTENT_URI} providing a directory of meds.
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.csi.meds";

/**
* The MIME type of a {@link #CONTENT_URI} sub-directory of a single Med.
*/
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.csi.meds";

/**
* The default sort order for this table
*/
public static final String DEFAULT_SORT_ORDER = "modified DESC";

/**
* The title of the Med
* <P>Type: TEXT</P>
*/
public static final String TITLE = "title";
public static final String sMEDS_FK = "MEDS_FK";
public static final String sSTATUS="STATUS";
public static final String sSOURCE = "SOURCE";
public static final String sPRODUCT = "PRODUCT";
public static final String sDIRECTIONS = "DIRECTIONS";
public static final String sFULLFILLHISTORY = "FULLFILLHISTORY";
public static final String sCREATION_DATE = "CREATION_DATE";
public static final String sMODIFIED_DATE = "MODIFIED_DATE";
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

Re: $100 via Paypal to help me fix a bug, Exception: column

Postby lihao.china » Mon Dec 01, 2008 6:52 am

sazabo wrote:Hello All,

I have a bug that I cannot find and I need another set of eyes. I will pay $100.00 for the answer/fix to this bug. Payment will be made via PayPal. This will also be an opportunity for more work in the future. This is a great site that gives great answers, I just want to pay to get it quicker. Please contact me if you are interested so I do not have multiple people working on the problem. I will only pay for one correct answer.

Check out my company site and my linkedin profile. I am legit and have been in business for a long time.
www.comsi.com
http://www.linkedin.com/in/jeffreyleebrandt

thanks,
Jeff

I am trying to use a ContentProvider and getting errors; The query with throws an exception. IllegalArgumentException: column '_id' does not exist

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

Insert is working:

long rowId = db.insert(MEDS_TABLE_NAME, Meds.MED, values);
Log.e(TAG, "aft insert rowId = " + rowId);
LOG --11-21 08:32:30.983: ERROR/MPhrProvider(195): aft insert rowId = 10

if (rowId > 0) {
Uri medUri = ContentUris.withAppendedId(MPhrDef.Meds.CONTENT_URI, rowId); // append rowid at end of givin uri

getContext().getContentResolver().notifyChange(medUri, null);
return medUri;

SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, null);
Log.e(TAG, "OnCreate cursor.getColumnName0 = " + c.getColumnName(0));
Log.e(TAG, "OnCreate cursor.getColumnName1 = " + c.getColumnName(1));

LogCat
11-24 09:29:23.199: ERROR/MPhrList(212): OnCreate cursor.getColumnName0 = _ID
11-24 09:29:25.347: ERROR/MPhrList(212): OnCreate cursor.getColumnName1 = SOURCE
________________________________________________________________________
Content Provider

public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + MEDS_TABLE_NAME + " ("
+ Meds._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"
+ ");");
Log.w(TAG, "onCreate");
}

public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

// String sTable = qb.getTables();

switch (sUriMatcher.match(uri)) {
case MEDS: // get all meds in db
qb.setTables(MEDS_TABLE_NAME);
qb.setProjectionMap(sMedsProjectionMap);
break;

case MED_ID: //get single med
qb.setTables(MEDS_TABLE_NAME);
qb.setProjectionMap(sMedsProjectionMap);
qb.appendWhere(Meds._ID + "=" + uri.getPathSegments().get(1));
break;

default:
throw new IllegalArgumentException("Unknown URI " + uri);
}

// If no sort order is specified use the default
String orderBy;
if (TextUtils.isEmpty(sortOrder)) {
orderBy = MPhrDef.Meds.DEFAULT_SORT_ORDER;
} else {
orderBy = sortOrder;
}

// Get the database and run the query
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, null);
Log.e(TAG, "OnCreate cursor.getColumnName0 = " + c.getColumnName(0));
Log.e(TAG, "OnCreate cursor.getColumnName1 = " + c.getColumnName(1));
/*
String[] p = {"_id", "SOURCE", "PRODUCT"};
String st = qb.buildQuery(p, selection, selectionArgs, null, null, orderBy, null);
st = ("select * from "+ MEDS_TABLE_NAME + "where(_id=3);");
Cursor cc =db.rawQuery(st, null);
*/
// Tell the cursor what uri to watch, so it knows when its source data changes
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}




_________________________________________________________________
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
Log.e(TAG, "OnCreate");
setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);

Intent intent = getIntent();
if (intent.getData() == null) {
intent.setData(Meds.CONTENT_URI);
}

// Inform the list we provide context menus for items
getListView().setOnCreateContextMenuListener(this);

setContentView(R.layout.medlist);

// Perform a managed query. The Activity will handle closing and re-querying the cursor
// when needed.

Uri uri = getIntent().getData();
Cursor cursor = managedQuery(uri, PROJECTION, null, null, Meds.DEFAULT_SORT_ORDER);
//Cursor cursor = managedQuery(Meds.CONTENT_URI, PROJECTION, null, null, null);

Log.e(TAG, "OnCreate cursor.getCount = " + cursor.getCount());
//Log.e(TAG, "OnCreate cursor.getInt(0) = " + cursor.getInt(0));
//cursor.copyStringToBuffer(1, new android.database.CharArrayBuffer(5));
Log.e(TAG, "OnCreate cursor.getColumnName0 = " + cursor.getColumnName(0));
Log.e(TAG, "OnCreate cursor.getColumnName1 = " + cursor.getColumnName(1));

/* Used to map meds entries from the database to views
*/
try{
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.mphrlist_item,
cursor,
new String[] { "PRODUCT" }, //from
new int[] { android.R.id.list }); //to
setListAdapter(adapter);
} catch (Exception e) {
Log.e(TAG, "Exception caught Simple.. ", e);


Exception Caught
11-24 09:29:50.237: ERROR/MPhrList(212): Exception caught Simple..
11-24 09:29:50.237: ERROR/MPhrList(212): java.lang.IllegalArgumentException: column '_id' does not exist
11-24 09:29:50.237: ERROR/MPhrList(212): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:310)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.CursorAdapter.init(CursorAdapter.java:111)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.CursorAdapter.<init>(CursorAdapter.java:90)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:46)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:84)
11-24 09:29:50.237: ERROR/MPhrList(212): at com.csi.android.mPHR.MPhrList.onCreate(MPhrList.java:102)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2103)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2156)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.ActivityThread.access$1800(ActivityThread.java:112)





public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + MEDS_TABLE_NAME + " ("
+ Meds._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"
+ ");");
Log.w(TAG, "onCreate");
}


please change the create table sql to below and try:
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + MEDS_TABLE_NAME + " ("
+ BaseColumns._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"
+ ");");
Log.w(TAG, "onCreate");
}
lihao.china
Freshman
Freshman
 
Posts: 3
Joined: Mon Dec 01, 2008 6:48 am
Location: beijing

Top

Postby MrSnowflake » Mon Dec 01, 2008 10:56 am

I guess that would be the same as Meds is derived from BaseColumns.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Meds

Postby sazabo » Mon Dec 01, 2008 4:43 pm

correct,

Jeff

public static final class Meds implements BaseColumns {
// This class cannot be instantiated
private Meds() {}

/**
* The content:// style URL for this table (tablename = meds)
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/meds");

/**
* The MIME type of {@link #CONTENT_URI} providing a directory of meds.
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.csi.meds";

/**
* The MIME type of a {@link #CONTENT_URI} sub-directory of a single Med.
*/
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.csi.meds";

/**
* The default sort order for this table
*/
public static final String DEFAULT_SORT_ORDER = "modified DESC";

/**
* The title of the Med
* <P>Type: TEXT</P>
*/
public static final String TITLE = "title";
public static final String _ID = "_id";
public static final String sMEDS_FK = "MEDS_FK";
public static final String sSTATUS="STATUS";
public static final String sSOURCE = "SOURCE";
public static final String sPRODUCT = "PRODUCT";
public static final String sDIRECTIONS = "DIRECTIONS";
public static final String sFULLFILLHISTORY = "FULLFILLHISTORY";
public static final String sCREATION_DATE = "CREATION_DATE";
public static final String sMODIFIED_DATE = "MODIFIED_DATE";
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

Re: Meds

Postby MrSnowflake » Mon Dec 01, 2008 11:27 pm

sazabo wrote:correct,
I know :p
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Re: Meds

Postby lihao.china » Tue Dec 02, 2008 2:59 am

sazabo wrote:correct,

Jeff

public static final class Meds implements BaseColumns {
// This class cannot be instantiated
private Meds() {}

/**
* The content:// style URL for this table (tablename = meds)
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/meds");

/**
* The MIME type of {@link #CONTENT_URI} providing a directory of meds.
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.csi.meds";

/**
* The MIME type of a {@link #CONTENT_URI} sub-directory of a single Med.
*/
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.csi.meds";

/**
* The default sort order for this table
*/
public static final String DEFAULT_SORT_ORDER = "modified DESC";

/**
* The title of the Med
* <P>Type: TEXT</P>
*/
public static final String TITLE = "title";
public static final String _ID = "_id";
public static final String sMEDS_FK = "MEDS_FK";
public static final String sSTATUS="STATUS";
public static final String sSOURCE = "SOURCE";
public static final String sPRODUCT = "PRODUCT";
public static final String sDIRECTIONS = "DIRECTIONS";
public static final String sFULLFILLHISTORY = "FULLFILLHISTORY";
public static final String sCREATION_DATE = "CREATION_DATE";
public static final String sMODIFIED_DATE = "MODIFIED_DATE";



i mean there is BaseColumns._ID already, so no need the one line code below in your class Meds to add the column _ID again
public static final String _ID = "_id";
i list my codes below, please look at it.
in DCDProvider.java file:
public static final class DCDMeta implements BaseColumns {
public static final Uri CONTENT_URI = Uri.parse("content://dcd/meta");
public static final String GENERATOR_NAME = "_generator_name";
public static final String GENERATOR_URL = "_generator_url";
public static final String GENERATOR_VERSION = "_generator_version";

public static final String ANCHOR = "_anchor";
public static final String TTL = "_ttl";
public static final String SERVER_TIME = "_server_time";
public static final String NEXT_URL = "_next_url";
public static final String REQUEST_EXIST_FLAG = "_request_exist_flag";
}


in DCDDatabaseHelper.java file:
private void createDCDTables(SQLiteDatabase db) {

db.execSQL("CREATE TABLE " + DCDProvider.TABLE_META + " ("
+ BaseColumns._ID + " INTEGER NOT NULL PRIMARY KEY,"
+ DCDMeta.ANCHOR + " TEXT,"
+ DCDMeta.GENERATOR_NAME + " TEXT,"
+ DCDMeta.GENERATOR_URL + " TEXT,"
+ DCDMeta.GENERATOR_VERSION + " TEXT,"
+ DCDMeta.SERVER_TIME + " TEXT,"
+ DCDMeta.NEXT_URL + " TEXT,"
+ DCDMeta.REQUEST_EXIST_FLAG + " TEXT,"
+ DCDMeta.TTL + " TEXT);");

}
lihao.china
Freshman
Freshman
 
Posts: 3
Joined: Mon Dec 01, 2008 6:48 am
Location: beijing

Postby MrSnowflake » Tue Dec 02, 2008 8:53 am

You are right! He shouldn't have defined Meds._ID again!
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby lihao.china » Tue Dec 02, 2008 9:35 am

by the way i think you'd better give the complete file named MPhrList.java(important, seems exception triggered by the file) and the related files with the provider including the file(use the provider) for us to locate the wrong place according to below log, it is hard to read you codes listed above to find the wrong code.


Exception Caught
11-24 09:29:50.237: ERROR/MPhrList(212): Exception caught Simple..
11-24 09:29:50.237: ERROR/MPhrList(212): java.lang.IllegalArgumentException: column '_id' does not exist
11-24 09:29:50.237: ERROR/MPhrList(212): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:310)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.CursorAdapter.init(CursorAdapter.java:111)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.CursorAdapter.<init>(CursorAdapter.java:90)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:46)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:84)
11-24 09:29:50.237: ERROR/MPhrList(212): at com.csi.android.mPHR.MPhrList.onCreate(MPhrList.java:102)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2103)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2156)
11-24 09:29:50.237: ERROR/MPhrList(212): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
lihao.china
Freshman
Freshman
 
Posts: 3
Joined: Mon Dec 01, 2008 6:48 am
Location: beijing

found that dup

Postby sazabo » Tue Dec 02, 2008 4:30 pm

Hello,

thanks I found the dup _id, thanks but that didn't solve the issue. The error is coming from the SimpleCursorAdapter. I think it may be something that I am doing with the xml files??

Jeff

public static final String TITLE = "title";
//public static final String _ID = "_id";
public static final String sMEDS_FK = "MEDS_FK";
public static final String sSTATUS="STATUS";
public static final String sSOURCE = "SOURCE";

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<!--
* Copyright (C) 2007 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->

<!-- Declare the contents of this Android application. The namespace
attribute brings in the Android plorm namespace, and the package
supplies a unique name for the application. When writing your
own application, the package name must be changed from "com.example.*"
to come from a domain that you own or have control over.
provider android:name="MPhrProvider" -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.csi.android.mPHR"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/csilogo12060"
android:label="@string/app_name"
>

<provider android:name="MPhrProvider"
android:authorities="com.csi.android.mPHR"
/>

<!-- call first screen to display main button selection -->
<activity android:name="MccrAct" android:label="Cognitive Solutions, Inc">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<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>

<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.VIEW" />
<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>

<activity android:name="MPhrEditor"
android:label="@string/title_med"
>
<!-- This filter says that we can view or edit the data of
a single note -->
<intent-filter android:label="@string/resolve_edit">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="com.android.notepad.action.EDIT_NOTE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.csi.meds" />
</intent-filter>

</activity>

<activity android:name="AddNewMed"
android:label="@string/new_med_label"
>
<!-- create a new med inside of a directory of notes. -->
<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>

<activity android:name=".About" android:label="@string/about_title" />


</application>
</manifest>
Attachments
MPhrList.java
(7.92 KiB) Downloaded 78 times
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

answer

Postby trungly » Sun Jan 18, 2009 7:30 am

Hi Jeff,

Did you find the answer to your problem yet?
I believe the solution is that when calling the SimpleCursorAdapter constructor, the String array you pass in for the 4th argument needs to include the "_id" string in it. I did not look at the Android source to see why, but it seems that they require the _ID to be there, otherwise the exception is thrown.

Code: Select all
      try{
         SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
               R.layout.mphrlist_item,
               cursor,
               new String[] { "_id", "PRODUCT" }, //from
               new int[] { android.R.id.product_id, android.R.id.list }); //to
         setListAdapter(adapter);
      } catch (Exception e) {
         Log.e(TAG, "Exception caught Simple.. ", e);
      }


If you do not wish the ID to show in the view, just set its visibility to "gone":

Code: Select all
   <TextView android:id="@+id/product_id"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:visibility="gone" />


Let me know if that does it.
trungly
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Jan 18, 2009 7:14 am

Postby chaoz1336 » Mon Jan 19, 2009 4:35 pm

just by the way...

@snowflake -> cant u put all the javacode in matchin BB-Tags... otherwise its very hard 2 read ;p
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Top
Next

Return to Jobs / Teams

Who is online

Users browsing this forum: No registered users and 3 guests