[英]Android app, No error message but has stopped unexpectedly
Does anyone know what is my problem. 有谁知道我的问题是什么。 I do not have any compile error messages however when i run the app it crashes and stops unexpectedly.
我没有任何编译错误消息,但是当我运行应用程序时,它崩溃并意外停止。
Here is my codes. 这是我的代码。 Thank you in advance.
先感谢您。
ListView l ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final_project);
String arr[]={"Red","Green","Blue","Yellow","Cyan"};
l=(ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, arr);
l.setAdapter(adapter);
Button buttonOne = (Button) findViewById(R.id.button1);
buttonOne.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
setContentView(R.layout.layout_save);
// setContentView(R.layout.activity_final_project);
//startActivity(new Intent("com.example.finalproject.layout_save"));
}
});
}
Give your ListView the appropriate id: 给您的ListView适当的ID:
<ListView android:id="@android:id/list"
...
</ListView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.