无法启动活动 ComponentInfo.....java.lang.IllegalStateException: 已附加 [英] Unable to start activity ComponentInfo.....java.lang.IllegalStateException: Already attached

查看:29
本文介绍了无法启动活动 ComponentInfo.....java.lang.IllegalStateException: 已附加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了那个错误,正如你所看到的,我正在添加我从第一个活动中获取的数据并将其存储到我在第二个活动中的数组中.然后我使用数组来填充列表视图.所以问题是每当我点击第一个视图上的保存按钮公共类 Main2Activity 扩展 AppCompatActivity {

I m getting that error ,as you can see i m adding the data that i grabbed from the first activity and storing it into the my array in the second activity . Then i use the array to populate the list view .So the problem is whenever i click to the save button on the first view public class Main2Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    super.onCreate(savedInstanceState);
    // setContentView(Your_Layout);
    //Bundle extras = null;
    //if(getIntent().getExtras() != null){
    //    extras = getIntent().getExtras();
    //}

    Intent intent = getIntent();
    //  ListView lv = (ListView) findViewById(R.id.View);

    String data = intent.getStringExtra("data");
    String first = intent.getStringExtra("stringOne");
    String second = intent.getStringExtra("stringTwo");
    String Third = intent.getStringExtra("stringThree");
    String Fourth = intent.getStringExtra("stringFour");
    String Fifth = intent.getStringExtra("stringFive");
    String Sixth = intent.getStringExtra("stringSix");

    // Find the ListView resource.
    ListView lv = (ListView) findViewById( R.id.View );

    // Create and populate a List of planet names.
    String[] dataUser = new String[] { first,second,Third,Fourth,Fifth,Sixth};
    ArrayList<String> dataList = new ArrayList<String>();
    dataList.addAll(Arrays.asList(dataUser));

    // Create ArrayAdapter using the planet list.
    ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dataList);

    // Set the ArrayAdapter as the ListView's adapter.
    lv.setAdapter(listAdapter);
}

}

推荐答案

您的代码中有 2 个 super.onCreate(savedInstanceState);,请删除其中一个.

You have 2 super.onCreate(savedInstanceState); in your code, remove one of them.

这篇关于无法启动活动 ComponentInfo.....java.lang.IllegalStateException: 已附加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆