我的 listview 适配器有问题。
请在下面检查我的代码:
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// TODO Auto-generated method stub
String selected;
selected = parent.getItemAtPosition(position).toString();
if( selected == "Apple" ){
Intent apple = new Intent(Fruits.this, Apples.class);
startActivity(apple);
}
else if( selected == "Apricot" ){
Intent apricot = new Intent(Fruits.this, Apricots.class);
startActivity(apricot);
}
else if( selected == "Avocado" ){
Intent avocado = new Intent(Fruits.this, Avocado.class);
startActivity(avocado);
}
} // end of OnItemClick method
每当我选择一行时,它都会在这一行抛出一个 nullpointerexception:
selected = parent.getItemAtPosition(position).toString();
这里有什么问题?请帮忙。谢谢。