I’ve got problem with my listview adapter.
Please check my code below:
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
Whenever I select a row, it’s throwing a nullpointerexception on this line:
selected = parent.getItemAtPosition(position).toString();
What is the problem here? please help. thanks.
As per your excpetion use the following code,
Also you have used,
Its not correct way to compare strings, Instead of it use,