Skip to content

Instantly share code, notes, and snippets.

@AdamMc331
Created April 25, 2015 01:00
Show Gist options
  • Save AdamMc331/1386ca37754270a7d80e to your computer and use it in GitHub Desktop.
Save AdamMc331/1386ca37754270a7d80e to your computer and use it in GitHub Desktop.
// onCreateLoader:
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
switch(id){
case ACCOUNT_LOADER:
return new CursorLoader(
getActivity(),
AccountEntry.buildAccountUri(mAccountID),
new String[]{
AccountEntry.TABLE_NAME + "." + AccountEntry._ID,
AccountEntry.COLUMN_BALANCE
},
null,
null,
null
);
}
}
// onLoadFinished
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
switch(loader.getId()){
case ACCOUNT_LOADER:
String[] cols = data.getColumnNames();
for(int i = 0; i < cols.length; i++){
Log.v("AccountLoader", cols[i]);
}
int index = data.getColumnIndex(AccountEntry.COLUMN_BALANCE);
Log.v("AccountLoader", "Index is: " + index + ".");
double balance = data.getDouble(data.getColumnIndex(AccountEntry.COLUMN_BALANCE));
break;
}
}
04-24 20:59:40.230 5163-5163/com.example.android.cashcaretaker V/AccountLoader﹕ _id
04-24 20:59:40.230 5163-5163/com.example.android.cashcaretaker V/AccountLoader﹕ accBalance
04-24 20:59:40.230 5163-5163/com.example.android.cashcaretaker V/AccountLoader﹕ Index is: 1.
04-24 20:59:40.231 5163-5163/com.example.android.cashcaretaker D/AndroidRuntime﹕ Shutting down VM
04-24 20:59:40.231 5163-5163/com.example.android.cashcaretaker E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.android.cashcaretaker, PID: 5163
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getDouble(AbstractWindowedCursor.java:86)
at android.database.CursorWrapper.getDouble(CursorWrapper.java:90)
at com.example.android.cashcaretaker.TransactionFragment.onLoadFinished(TransactionFragment.java:163)
at com.example.android.cashcaretaker.TransactionFragment.onLoadFinished(TransactionFragment.java:27)
at android.support.v4.app.LoaderManagerImpl$LoaderInfo.callOnLoadFinished(LoaderManager.java:427)
at android.support.v4.app.LoaderManagerImpl$LoaderInfo.onLoadComplete(LoaderManager.java:395)
at android.support.v4.content.Loader.deliverResult(Loader.java:104)
at android.support.v4.content.CursorLoader.deliverResult(CursorLoader.java:73)
at android.support.v4.content.CursorLoader.deliverResult(CursorLoader.java:35)
at android.support.v4.content.AsyncTaskLoader.dispatchOnLoadComplete(AsyncTaskLoader.java:223)
at android.support.v4.content.AsyncTaskLoader$LoadTask.onPostExecute(AsyncTaskLoader.java:61)
at android.support.v4.content.ModernAsyncTask.finish(ModernAsyncTask.java:461)
at android.support.v4.content.ModernAsyncTask.access$500(ModernAsyncTask.java:47)
at android.support.v4.content.ModernAsyncTask$InternalHandler.handleMessage(ModernAsyncTask.java:474)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment