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)




