Home » Android » android – Unable to start activity ComponentInfo…..java.lang.IllegalStateException: Already attached

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

Posted by: admin June 15, 2020 Leave a comment

Questions:

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

}

How to&Answers:

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

Answer:

So I did remove the extrat super.onCreate(savedInstanceState); that i had but it looks like one of my edit text is passing a nul value .So i went trough every line but as you can see all the edixtext are passing a diffrent of null
http://pastebin.com/mys3R8QQ