So I have a Cursor that is getting a result from a query to the application datab开发者_JAVA百科ase. I know that there is at least one correct entry in the database since I was able to retrieve the string from the row previously.
I then changed some of the logic to accommodate the result and am suddenly getting null returned when calling c.getString(0). The relevant code is posted below.
I'm new to Android and Java, so I might be missing some subtlety that's causing the problem.
Cursor c = context.getContentResolver().query(tempJobName.build(),
null, null, null, null);
for (c.moveToFirst(); c.isAfterLast() == false; c.moveToNext())
{
Log.w(TAG, c.getString(0));
if (c.getString(0).equalsIgnoreCase(jobName))
{
existed = true;
break;
}
}
You might want to add more details. But since you did find some records, the solution for your problem is easy. Could you please replace this line with this? ( First column of table might change right :))
c.getString(0);
with
int columnIndex = c.getColumnIndex(COLUMN_NAME);// You could also use getcolumnIndexorThrow variant.
c.getString(columnIndex);
if this does not work, then your table does not have the column. You are simply barking up the wrong tree.
精彩评论