0
我正在开发一个应用程序,我在一个扩展选项卡活动的类下创建数据库。但是当我的选项卡活动恢复时,我的应用程序崩溃。任何帮助,将不胜感激。TabActivity不恢复
这里是我的代码
public class MainActivity extends TabActivity {
/** Called when the activity is first created. */
public static boolean paid=false;
public String num;
public String num1;
public String name;
static int delay;
public static Boolean fromapp=false;
SQLiteDatabase db;
TabHost tabHost;
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(getApplicationContext(), String.valueOf(fromapp), Toast.LENGTH_SHORT).show();
Resources res = getResources(); // Resource object to get Drawables
tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
/*
intent = new Intent().setClass(this, DialPad.class);
spec = tabHost.newTabSpec("DIAL PAD").setIndicator("DIAL PAD",res.getDrawable(R.drawable.ic_launcher)).setContent(intent);
tabHost.addTab(spec);*/
intent = new Intent().setClass(this, Calllog.class);
spec = tabHost.newTabSpec("CALL LOG").setIndicator("CALL LOG",res.getDrawable(R.drawable.ic_launcher)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Contacts.class);
spec = tabHost.newTabSpec("CONTACTS").setIndicator("CONTACTS",res.getDrawable(R.drawable.ic_launcher)).setContent(intent);
tabHost.addTab(spec);
db=openOrCreateDatabase("Mydb", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS Fromapp(delay INTEGER);");
Cursor c=db.rawQuery("select * from Fromapp", null);
if(c.moveToFirst())
{
}
else
{
db.execSQL("insert into Fromapp values("+5000+")");
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.ten:
db.execSQL("update Fromapp set delay="+10000);
return true;
case R.id.twenty:
db.execSQL("update Fromapp set delay="+20000);
return true;
case R.id.fifty:
db.execSQL("update Fromapp set delay="+30000);
return true;
case R.id.hundred:
db.execSQL("update Fromapp set delay="+40000);
return true;
case R.id.twohundred:
db.execSQL("update Fromapp set delay="+50000);
return true;
case R.id.fivehundred:
db.execSQL("update Fromapp set delay="+60000);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
我logcat的显示下方
11-01 12:28:49.513: E/AndroidRuntime(32547): FATAL EXCEPTION: main
11-01 12:28:49.513: E/AndroidRuntime(32547): java.lang.RuntimeException: Unable to resume activity {com.thoughtrix.tryamisscall/com.thoughtrix.tryamisscall.MainActivity}: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2742)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1276)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.os.Handler.dispatchMessage(Handler.java:99)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.os.Looper.loop(Looper.java:137)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-01 12:28:49.513: E/AndroidRuntime(32547): at java.lang.reflect.Method.invokeNative(Native Method)
11-01 12:28:49.513: E/AndroidRuntime(32547): at java.lang.reflect.Method.invoke(Method.java:511)
11-01 12:28:49.513: E/AndroidRuntime(32547): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-01 12:28:49.513: E/AndroidRuntime(32547): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-01 12:28:49.513: E/AndroidRuntime(32547): at dalvik.system.NativeStart.main(Native Method)
11-01 12:28:49.513: E/AndroidRuntime(32547): Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.database.BulkCursorToCursorAdaptor.throwIfCursorIsClosed(BulkCursorToCursorAdaptor.java:64)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.database.BulkCursorToCursorAdaptor.requery(BulkCursorToCursorAdaptor.java:133)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.database.CursorWrapper.requery(CursorWrapper.java:186)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.Activity.performRestart(Activity.java:5148)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.ActivityThread.performRestartActivity(ActivityThread.java:3214)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:168)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:523)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.ActivityGroup.onResume(ActivityGroup.java:61)
11-01 12:28:49.513: E/AndroidRuntime(32547): at com.thoughtrix.tryamisscall.MainActivity.onResume(MainActivity.java:134)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.Activity.performResume(Activity.java:5182)
11-01 12:28:49.513: E/AndroidRuntime(32547): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2732)
11-01 12:28:49.513: E/AndroidRuntime(32547): ... 10 more