我得到了这个错误,因为你可以看到我添加了我从第一个活动中抓取的数据并将其存储到第二个活动中的我的数组中.然后我使用数组来填充列表视图.所以问题是每当我点击第一个视图上的保存按钮时 公共类Main2Activity扩展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}; ArrayListdataList = new ArrayList (); dataList.addAll(Arrays.asList(dataUser)); // Create ArrayAdapter using the planet list. ArrayAdapter listAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, dataList); // Set the ArrayAdapter as the ListView's adapter. lv.setAdapter(listAdapter); }
}
您super.onCreate(savedInstanceState);
的代码中有2个,删除其中一个.