How can i fix my null pointer exception

后端 未结 5 1267
生来不讨喜
生来不讨喜 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:20

    Initialize your adapter in OnCreateView() and before adding any value,

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

    here taskNames can an array or arrayList of task names which you would have defined as,

        ArrayList taskNames; // or String[] taskNames;
    

    Let me know if it works for you...

    And do mark it as answer so that it would be useful to others...

提交回复
热议问题