我的应用程序抛出错误:
11-08 17:19:40.800: E/AndroidRuntime(18592): java.lang.RuntimeException: Unable to resume activity {app.piotrek.learning/app.piotrek.learning.AddNewQuestion}: java.lang.IllegalStateException: trying to requery an already closed cursor android.database.sqlite.SQLiteCursor@40f7f8a8
11-08 17:19:40.800: E/AndroidRuntime(18592): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2567)
11-08 17:19:40.800: E/AndroidRuntime(18592): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2595)
11-08 17:19:40.800: E/AndroidRuntime(18592): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1183)
11-08 17:19:40.800: E/AndroidRuntime(18592): at android.os.Handler.dispatchMessage(Handler.java:99)
11-08 17:19:40.800: E/AndroidRuntime(18592): at android.os.Looper.loop(Looper.java:137)
11-08 17:19:40.800: E/AndroidRuntime(18592): at android.app.ActivityThread.main(ActivityThread.java:4575)
11-08 17:19:40.800: E/AndroidRuntime(18592): at java.lang.reflect.Method.invokeNative(Native Method)
11-08 17:19:40.800: E/AndroidRuntime(18592): at java.lang.reflect.Method.invoke(Method.java:511)
11-08 17:19:40.800: E/AndroidRuntime(18592): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
11-08 17:19:40.800: E/AndroidRuntime(18592): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
11-08 17:19:40.800: E/AndroidRuntime(18592): at dalvik.system.NativeStart.main(Native Method)
11-08 17:19:40.800: E/AndroidRuntime(18592): Caused by: java.lang.IllegalStateException: trying to requery an already closed cursor android.database.sqlite.SQLiteCursor@40f7f8a8
11-08 17:19:40.800: E/AndroidRuntime(18592): at android.app.Activity.performRestart(Activity.java:4508)
11-08 17:19:40.800: E/AndroidRuntime(18592): at android.app.Activity.performResume(Activity.java:4531)
11-08 17:19:40.800: E/AndroidRuntime(18592): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2557)
11-08 17:19:40.800: E/AndroidRuntime(18592): ... 10 more
当我去另一个活动并点击“后退按钮”时,似乎出现错误。 我已经发现问题就在这里:
@Override
protected void onResume(){
super.onResume();
db = new Database(getApplicationContext());
db.open();
fillSpinner(db.getAllEntriesSubjects(), spinnerSubject, DatabaseData.KEY_NAME);
//long data = spinnerSubject.getSelectedItemId();
//Log.v("ADDNEWQUESTION", "Wybrano: " + data);
//fillSpinner(db.getAllEntriesTitles(), spinnerTitles);
db.close();
}
public void fillSpinner(Cursor cs, Spinner spinner, String dane){
startManagingCursor(cs);
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cs, new String[] {dane}, new int[] {android.R.id.text1});
mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
spinner.setAdapter(mAdapter);
}
AFAIK,我没有关闭任何光标。那怎么了?
答案 0 :(得分:0)
从db.close();
方法中删除onResume
并将其添加到onPause()
方法。
希望它有所帮助。
答案 1 :(得分:0)
试试这个..
public void onBackPressed(){
Intent i = new Intent(getApplicationContext(), AddNewQuestion.class);
startActivity(i);
finish();
super.onStop();
}