How can i fix my null pointer exception

后端 未结 5 1220
生来不讨喜
生来不讨喜 2021-01-24 15:58

I\'ve been trying to fix this null pointer exception but I cant. I know its pointing to a null object but I don\'t how to fix it. I am beginner in Java programming so please don

5条回答
  •  失恋的感觉
    2021-01-24 16:25

    You haven't created an instance of an ArrayAdapter for your itemsAdapter variable when you try to call the add() method on it.

    Try to initialise it using:

    itemsAdapter = new ArrayAdapter(this,
        android.R.layout.simple_list_item_1, values);
    

    Note: values is either a String[] or List so you'll need to pass that in correctly

提交回复
热议问题