java - asynctask fatal exception #1 in loadermanager -
i have problem loadermanager should extracts data contentprovider. error :
06-27 10:14:29.053: e/androidruntime(2270): fatal exception: asynctask #1 06-27 10:14:29.053: e/androidruntime(2270): process: com.trackme, pid: 2270 06-27 10:14:29.053: e/androidruntime(2270): java.lang.runtimeexception: error occured while executing doinbackground() 06-27 10:14:29.053: e/androidruntime(2270): @ android.os.asynctask$3.done(asynctask.java:300) 06-27 10:14:29.053: e/androidruntime(2270): @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) 06-27 10:14:29.053: e/androidruntime(2270): @ java.util.concurrent.futuretask.setexception(futuretask.java:222) 06-27 10:14:29.053: e/androidruntime(2270): @ java.util.concurrent.futuretask.run(futuretask.java:242) 06-27 10:14:29.053: e/androidruntime(2270): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) 06-27 10:14:29.053: e/androidruntime(2270): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) 06-27 10:14:29.053: e/androidruntime(2270): @ java.lang.thread.run(thread.java:841) 06-27 10:14:29.053: e/androidruntime(2270): caused by: java.lang.indexoutofboundsexception`
and code :
public class routeslistactivity extends listactivity implements loadermanager.loadercallbacks<cursor>{ public static final string tag = "routelist"; private static final int loader_id = 1; public static final int activity_create = 0; public static final int activity_results = 1; private simplecursoradapter mroutescursoradapter; @override protected void oncreate(bundle savedinstancestate){ log.i(tag, "oncreate della lista "); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_routes_list); string[] = new string[] {geoprovider.key_rowid}; int[] = new int[] {r.id.route1}; mroutescursoradapter = new simplecursoradapter(this, r.layout.route_row, null, from, to, 0); setlistadapter(mroutescursoradapter); //permette di interfacciare l'activity col loader loadermanager lm = getloadermanager(); lm.initloader(loader_id, null, this); registerforcontextmenu(getlistview()); log.i(tag, "fine del metodo oncreate"); } public boolean oncreateoptionmenu(menu menu) { log.i(tag, "creazione dell'optionmenu"); super.oncreateoptionsmenu(menu); getmenuinflater().inflate(r.menu.routes_list, menu); return true; } public boolean onoptionitemselected(menuitem item) { log.i(tag, "selezione dell'item del menu "); super.onoptionsitemselected(item); switch(item.getitemid()) { case r.id.create_route: createroute(); return true; } return super.onoptionsitemselected(item); } @override protected void onlistitemclick(listview l, view v, int position, long id) { log.i(tag, "selezione elemento della lista "); super.onlistitemclick(l, v, position, id); showresults(id); } @override public void oncreatecontextmenu(contextmenu menu, view v, contextmenuinfo menuinfo){ super.oncreatecontextmenu(menu, v, menuinfo); getmenuinflater().inflate(r.menu.context, menu); } @override protected void onactivityresult(int requestcode, int resultcode, intent intent) { super.onactivityresult(requestcode, resultcode, intent); } private void createroute(){ log.i(tag , "createroute"); intent toroute = new intent(this, geoactivity.class); startactivityforresult(toroute, activity_create); } private void deleteroute(long id) { log.i(tag , "deleteroute"); uri baseuri = geoprovider.geo_table_uri; long idwrapper = long.valueof(id); getcontentresolver().delete(uri.withappendedpath(baseuri, idwrapper.tostring()), null, null); } private void showresults(long id){ log.i(tag , "showresults"); intent toresults = new intent(this, results.class); toresults.putextra(geoprovider.key_rowid, id); startactivityforresult(toresults, activity_results); } //il loader serve per il caricamento asincrono dei dati dal db @override public loader<cursor> oncreateloader(int id, bundle args){ log.i(tag , "oncreateloader"); return new cursorloader(this, geoprovider.geo_table_uri, new string[] {geoprovider.key_rowid}, null, null, null); } @override public void onloadfinished(loader<cursor> loader, cursor cursor) { log.i(tag , "onloadfinished"); switch(loader.getid()){ case loader_id: log.i(tag , "onloadfinished case loader_id"); mroutescursoradapter.swapcursor(cursor); break; } log.i(tag , "fine onloadfinished"); } @override public void onloaderreset(loader<cursor> arg0){ mroutescursoradapter.swapcursor(null); }
}
i can't understand why i'm getting error not using class asynctask! contentprovider should ok , in opinion error here don't know where...
thanks
you getting indexoutofboundsexception in asynctask. means trying access index outside range of array. example in code:
int[] x = new int[5]; // x has size 5 int y = x[10]; // outofbounds since x has size of 5, , trying access 11th element (index 10)
your example shows activity cannot find , have change asynctask, can view this related question see example of indexoutofboundsexception.
Comments
Post a Comment