我正在开发一个小项目,我得到一个错误,无法解决显示强制关闭应用程序。任何人都可以帮助我
这是我的screen3代码
public class screen3 extends ListActivity {
/** Called when the activity is first created. */
String[] names = new String[] { "India", "Malaysia"};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen3);
// Create an array of Strings, that will be put to our ListActivity
// Use your own layout and point the adapter to the UI elements which
// contains the label
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.screen3,
R.id.label, names));
Button b4=(Button)findViewById(R.id.click);
b4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i2 =new Intent(screen3.this,screen4.class);
startActivity(i2);
}
});
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
if(keyword.equals("India"))
{
Intent i=new Intent(screen3.this,new21.class);
startActivity(i);
}
Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG)
.show();
}
}
和 26行代码是
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i2 =new Intent(screen3.this,screen4.class);
startActivity(i2);
我检查过它很好
答案 0 :(得分:0)
在Screen3 onCreate方法中,第26行有一个空指针异常...