In my application I am retrieving contact data using a Loader. I have debugged the application and find that the application crashes on the first statement that occurs in the onLoadFinished callback.
Here is the code:
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
Log.d("Loader","Load Finished");
mAdapter.changeCursor(arg1);
phonenumber_enter.setAdapter(mAdapter);
}
I am finding that the application crashes on the first line in the callback(in this case the application crashes when the message is logged). Here is the logcat:
02-05 21:31:07.357: E/AndroidRuntime(31707): java.lang.RuntimeException: An error occured while executing doInBackground()
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:137)
02-05 21:31:07.357: E/AndroidRuntime(31707): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
02-05 21:31:07.357: E/AndroidRuntime(31707): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
02-05 21:31:07.357: E/AndroidRuntime(31707): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-05 21:31:07.357: E/AndroidRuntime(31707): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-05 21:31:07.357: E/AndroidRuntime(31707): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-05 21:31:07.357: E/AndroidRuntime(31707): at java.lang.Thread.run(Thread.java:841)
02-05 21:31:07.357: E/AndroidRuntime(31707): Caused by: java.lang.IllegalArgumentException: Invalid column data1
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.content.ContentResolver.query(ContentResolver.java:461)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.content.ContentResolver.query(ContentResolver.java:404)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:35)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:242)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:51)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:40)
02-05 21:31:07.357: E/AndroidRuntime(31707): at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:123)
02-05 21:31:07.357: E/AndroidRuntime(31707): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
I see that there is no data1 column but that shouldn't make a difference because the Cursor loader is created as follows:
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
return new CursorLoader(getActivity(),
ContactsContract.Contacts.CONTENT_URI, null, null, null,
null);
}
Since the projection is null I thought that all the possible columns would be selected. After debugging, I found that there is no column in the cursor called data1. Any thoughts would be much appreciated.
EDIT: I have just tested the application and it seems that the crash doesnt occur when I have a debugger attached to the application. Though no cursor is returned so it seems that the loader is not correctly working.
EDIT 2: Ok so I debugged the application again and saw all the columns that the cursor is returning. No column contains phone numbers. Here is the original statement:
CursorLoader(getActivity(),
ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
Any ideas?