ArrayList 的nullpointerexception为什么空指针了
毕业设计
1
public class MainActivity extends Activity {
private List fruitList = new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initFruit();
FruitAdapter adapter = new FruitAdapter(MainActivity.this, R.layout.fruit_item, fruitList);
ListView listView = (ListView)findViewById(R.id.fruit_view1);
listView.setAdapter(adapter);
}
private void initFruit() {
// TODO Auto-generated method stub
Fruit apple = new Fruit("Apple",R.drawable.ic_launcher);
fruitList.add(apple);
Fruit banana = new Fruit("Apple",R.drawable.ic_launcher);
fruitList.add(banana);
}
}
发表回复