こんにちは私は私のlistivewに問題があります。以下の私のコードを確認してください:
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// TODO Auto-generated method stub
String selected;
//selected = parent.getItemAtPosition(position).toString();
selected = parent.getItemAtPosition(lv.getFirstVisiblePosition() + position).toString();
if( selected.equals("Apple") ){
Intent apple = new Intent(Fruits.this, Apples.class);
startActivity(apple);
}
else if( selected.equals("Apricot") ){
Intent apricot = new Intent(Fruits.this, Apricots.class);
startActivity(apricot);
}
else if( selected.equals("Avocado") ){
Intent avocado = new Intent(Fruits.this, Avocado.class);
startActivity(avocado);
}
else if( selected.equals("Banana") ){
Intent banana = new Intent(Fruits.this, Banana.class);
startActivity(banana);
}
else if( selected.equals("Blackberry") ){
Intent blackberry = new Intent(Fruits.this, Blackberries.class);
startActivity( blackberry );
}
else if( selected.equals("Blueberry") ){
Intent blueberry = new Intent(Fruits.this, Blueberry.class);
startActivity(blueberry);
}
else if( selected.equals("Cranberry") ){
Intent cranberry = new Intent(Fruits.this, Cranberry.class);
startActivity(cranberry);
}
else if( selected.equals("Figs") ){
Intent fig = new Intent(Fruits.this, Figs.class);
startActivity(fig);
}
else if( selected.equals("Grapefruit") ){
Intent grapefruit = new Intent(Fruits.this, Grapefruit.class);
startActivity(grapefruit);
}
else if( selected.equals("Kiwi") ){
Intent kiwi = new Intent(Fruits.this, Kiwi.class);
startActivity(kiwi);
}
else if( selected.equals("Lemon") ){
Intent lemon = new Intent(Fruits.this, Lemons.class);
startActivity(lemon);
}
else if( selected.equals("Melon") ){
Intent melon = new Intent(Fruits.this, Melon.class);
startActivity(melon);
}
else if( selected.equals("Orange") ){
Intent orange = new Intent(Fruits.this, Orange.class);
startActivity(orange);
}
else if( selected.equals("Papaya") ){
Intent papaya = new Intent(Fruits.this, Papaya.class);
startActivity(papaya);
}
else if( selected.equals("Peach") ){
Intent peach = new Intent(Fruits.this, Peaches.class);
startActivity(peach);
}
else if( selected.equals("Pear") ){
Intent pear = new Intent(Fruits.this, Pears.class);
startActivity(pear);
}
else if( selected.equals("Pineapple") ){
Intent pineapple = new Intent(Fruits.this, Pineapple.class);
startActivity(pineapple);
}
else if( selected.equals("Plum") ){
Intent plum = new Intent(Fruits.this, Plum.class);
startActivity(plum);
}
else if( selected.equals("Prune") ){
Intent prune = new Intent(Fruits.this, Prunes.class);
startActivity(prune);
}
else if( selected.equals("Raspberry") ){
Intent raspberry = new Intent(Fruits.this, Raspberry.class);
startActivity(raspberry);
}
else if( selected.equals("Rhubarb") ){
Intent rhubard = new Intent(Fruits.this, Rhubard.class);
startActivity(rhubard);
}
else if( selected.equals("Strawberry") ){
Intent strawberry = new Intent(Fruits.this, Strawberries.class);
startActivity(strawberry);
}
} // end of OnItemClick method
final String[] classes = new String[] {
"Apple", // #0
"Apricot", // #1
"Avocado", // #2
"Banana", // #3
"Blackberry", // #4
"Blueberry", // #5
"Cranberry", // #6
"Figs", // #7
"Grapefruit", // #8
"Kiwi", // #9
"Lemon", // #10
"Melon", // #11
"Orange", // #12
"Papaya", // #13
"Peach", // #14
"Pear", // #15
"Pineapple", // #16
"Plum", // #17
"Prune", // #18
"Raspberry", // #19
"Rhubarb", // #20
"Strawberry" // #21
};
アプリケーションを実行するたびに、次の行にnullpointerexceptionがスローされます。
selected = parent.getItemAtPosition(lv.getFirstVisiblePosition() + position).toString();
私のコードの何が問題になっていますか?どんな助けでも本当にありがたいです。ありがとう。