nullPointerException in multi column list using hashmap

后端 未结 3 1665
悲&欢浪女
悲&欢浪女 2021-01-25 13:47

I already tried references from similar question on SO, but hasn\'t got the appropriate solution.

I\'m trying to fetch the data from a webpage and displ

相关标签:
3条回答
  • 2021-01-25 14:01

    You are creating the listViewAdapter in the onCreate of MultiCol and passing in a reference to list. However, at that point list has not been instantiated yet, since that does not happen until your AsyncTask finishes. In other words: you're passing in null, hence the nullpointer exception in LogCat.

    To correct this, you'll probably want to move the following two lines of code to the end of the onPostExecute() of your DownloadWebPageTask:

    listviewAdapter adapter = new listviewAdapter(this, list);
    lview.setAdapter(adapter);
    

    That way you will supply the adapter with an instantiated (non-null) list object.

    0 讨论(0)
  • 2021-01-25 14:18
    Caused by: java.lang.NullPointerException
    12-07 11:40:19.767: E/AndroidRuntime(2283):     at com.multicol.listviewAdapter.getCount(listviewAdapter.java:31)
    

    The exception is at the getCount() method. List is null. Instantiate it

     private ArrayList<HashMap<String, String>> list=new ArrayList({});
    

    Give a try

    0 讨论(0)
  • 2021-01-25 14:18

    I think the error was got for the layout object as you pass the this into the listviewAdapter() constructor and get the layout in that that means you retrieving the current activity layout which was set by setcontentview() and that is your main.xml layout. while for the control or object for the textview for custom list you need to pass that layout resource id when you layout the inflate time. just check that first you got the error where and write the comment on that line in code

    LayoutInflater inflater = activity.getLayoutInflater();
    

    I think here you getting the main.xml file layout instead of listview_row.xml

    0 讨论(0)
提交回复
热议问题