Giupin
23-12-2012, 12:16
Salve a tutti, vorrei richiamare un'activity che visualizzi dei dati ricavati da un database sqlite su una gridview ma ottengo questo errore all'initLoader:
AsyncTaskLoader$LoadTask.onPostExecute(Object) line: 63
AsyncTaskLoader$LoadTask(ModernAsyncTask).finish(Object) line: 461
ModernAsyncTask.access$500(ModernAsyncTask, Object) line: 47
ModernAsyncTask$InternalHandler.handleMessage(Message) line: 474
ModernAsyncTask$InternalHandler(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: not available [native method]
questo č il codice
import android.database.Cursor;
import android.os.Bundle;
import android.widget.GridView;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v4.app.FragmentActivity;
import android.net.Uri;
import it.giupint.data.*;
public class ShowResults extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor>{
private DbCantiAdapter dbCanti;
private Cursor cursor;
private SimpleCursorAdapter adapter;
//private Context thisContext = getApplicationContext();
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
String[] projection = {DbCantiAdapter.KEY_IDCANTO, DbCantiAdapter.KEY_TITOLO };
CursorLoader cursorLoader = new CursorLoader(this, Uri.EMPTY, projection, null, null, null);
return cursorLoader;
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
adapter.swapCursor(cursor);
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
adapter.swapCursor(null);
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_results);
dbCanti = new DbCantiAdapter(this.getBaseContext());
dbCanti.open();
dbCanti.addCanti(1, "Shemą", 1, "Bianco", "Ordinario", "Risposta", "--");
Bundle bundle = this.getIntent().getExtras();
cursor = dbCanti.fetchCantiByFilters(bundle.getBoolean("Parola"), bundle.getBoolean("Eucarestia"));
//String contactID = cursor.getString(cursor.getColumnIndex(DbCantiAdapter.KEY_IDCANTO));
GridView grvCanti = (GridView)findViewById(R.id.gridViewCanti);
String[] cols = new String[] {DbCantiAdapter.KEY_TITOLO, DbCantiAdapter.KEY_PERIODO, DbCantiAdapter.KEY_TIPOALT};
int[] views = new int[] {android.R.id.text1, android.R.id.text2, android.R.id.text2 };
adapter = new SimpleCursorAdapter(this, R.layout.show_results, null, cols, views, 0);
grvCanti.setAdapter(adapter);
cursor.close();
getSupportLoaderManager().initLoader(0, null, this);
dbCanti.close();
}
}
AsyncTaskLoader$LoadTask.onPostExecute(Object) line: 63
AsyncTaskLoader$LoadTask(ModernAsyncTask).finish(Object) line: 461
ModernAsyncTask.access$500(ModernAsyncTask, Object) line: 47
ModernAsyncTask$InternalHandler.handleMessage(Message) line: 474
ModernAsyncTask$InternalHandler(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: not available [native method]
questo č il codice
import android.database.Cursor;
import android.os.Bundle;
import android.widget.GridView;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v4.app.FragmentActivity;
import android.net.Uri;
import it.giupint.data.*;
public class ShowResults extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor>{
private DbCantiAdapter dbCanti;
private Cursor cursor;
private SimpleCursorAdapter adapter;
//private Context thisContext = getApplicationContext();
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
String[] projection = {DbCantiAdapter.KEY_IDCANTO, DbCantiAdapter.KEY_TITOLO };
CursorLoader cursorLoader = new CursorLoader(this, Uri.EMPTY, projection, null, null, null);
return cursorLoader;
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
adapter.swapCursor(cursor);
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
adapter.swapCursor(null);
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_results);
dbCanti = new DbCantiAdapter(this.getBaseContext());
dbCanti.open();
dbCanti.addCanti(1, "Shemą", 1, "Bianco", "Ordinario", "Risposta", "--");
Bundle bundle = this.getIntent().getExtras();
cursor = dbCanti.fetchCantiByFilters(bundle.getBoolean("Parola"), bundle.getBoolean("Eucarestia"));
//String contactID = cursor.getString(cursor.getColumnIndex(DbCantiAdapter.KEY_IDCANTO));
GridView grvCanti = (GridView)findViewById(R.id.gridViewCanti);
String[] cols = new String[] {DbCantiAdapter.KEY_TITOLO, DbCantiAdapter.KEY_PERIODO, DbCantiAdapter.KEY_TIPOALT};
int[] views = new int[] {android.R.id.text1, android.R.id.text2, android.R.id.text2 };
adapter = new SimpleCursorAdapter(this, R.layout.show_results, null, cols, views, 0);
grvCanti.setAdapter(adapter);
cursor.close();
getSupportLoaderManager().initLoader(0, null, this);
dbCanti.close();
}
}