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);
}

}

回复

共2条回复 我来回复
  • 代码客栈
    这个人很懒,什么都没有留下~
    评论

    private List fruitList = new ArrayList();

    这个加一个static试试 private static List fruitList = new ArrayList();

    0条评论
  • 代码港湾
    这个人很懒,什么都没有留下~
    评论

    ListView listView = (ListView)findViewById(R.id.fruit view1); 查看这句是否有误。检查布局文件:fruit item

    0条评论

发表回复

登录后才能评论