Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to start activity ComponentInfo.....java.lang.IllegalStateException: Already attached

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);
}

}

like image 260
Ngoma Mbaku Davy Avatar asked Feb 02 '16 20:02

Ngoma Mbaku Davy


1 Answers

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

like image 82
Malek Hijazi Avatar answered Nov 03 '22 10:11

Malek Hijazi