单击关闭按钮后,应用程序已停止

时间:2018-01-21 11:45:04

标签: android android-intent android-activity

我正在开发一个Android应用程序,但我的应用程序正在停止

这是我做的步骤:我...
 1.我正在使用选项卡式活动,并且有一个列表视图
 2. listView中的每个元素都注册了上下文菜单
 3.第一个选项是上下文菜单用于编辑视图的信息
 4.单击它后,将打开另一个活动(使用意图)

错误是当我在新活动打开时点击关闭按钮时,我遇到错误:“不幸的是app停止了”

编辑课程:

public class Editor extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_editor);

        Intent intent = getIntent();
        int position = intent.getIntExtra("POSITION", -1);
        TextView t = (TextView)findViewById(R.id.intentResult);
        t.setText(position+"");
    }
}

意图召唤:

public boolean onContextItemSelected(MenuItem item) {
    if(item.getItemId()==EDIT_ID){

    }
    else if(item.getItemId()==DELETE_ID){
        AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();

        Intent intent = new Intent(getContext(), Editor.class);
        intent.putExtra("POSITION", acmi.position);
        startActivity(intent);
    }
    return super.onContextItemSelected(item);
}

// acmi只是一个整数

  

错误:01-21 16:54:59.714 2820-2820 / com.example.abu_bakr.darsjadvali   E / AndroidRuntime:致命异常:主要                                                                                   处理:com.example.abu_bakr.darsjadvali,PID:2820                                                                                   java.lang.RuntimeException:无法恢复活动   {com.example.abu_bakr.darsjadvali / com.example.abu_bakr.darsjadvali.MainActivity}:   java.lang.IllegalStateException:尝试重新查询已经关闭的   cursor android.database.sqlite.SQLiteCursor@2e3a8e12                                                                                       在   android.app.ActivityThread.performResumeActivity(ActivityThread.java:3033)                                                                                       在   android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3064)                                                                                       在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1353)                                                                                       在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                       在android.os.Looper.loop(Looper.java:135)                                                                                       在android.app.ActivityThread.main(ActivityThread.java:5356)                                                                                       at java.lang.reflect.Method.invoke(Native Method)                                                                                       在java.lang.reflect.Method.invoke(Method.java:372)                                                                                       在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:908)                                                                                       在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)                                                                                    引起:java.lang.IllegalStateException:试图重新查询   已关闭游标android.database.sqlite.SQLiteCursor@2e3a8e12                                                                                       在android.app.Activity.performRestart(Activity.java:6076)                                                                                       在android.app.Activity.performResume(Activity.java:6099)                                                                                       在   android.app.ActivityThread.performResumeActivity(ActivityThread.java:3022)                                                                                       在   android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3064)                                                                                       在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1353)                                                                                       在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                       在android.os.Looper.loop(Looper.java:135)                                                                                       在android.app.ActivityThread.main(ActivityThread.java:5356)                                                                                       at java.lang.reflect.Method.invoke(Native Method)                                                                                       在java.lang.reflect.Method.invoke(Method.java:372)                                                                                       在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:908)                                                                                       在com

     

.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)

1 个答案:

答案 0 :(得分:0)

正如您的错误日志所述,它是数据库异常。

发布您MainActivity的完整代码,以便我们了解正在进行的操作