BaseAdapter class wont setAdapter inside Asynctask - Android

后端 未结 4 540
谎友^
谎友^ 2020-12-02 02:52

I have asynctask that gathers usernames, comments, and numbers. It places them into strings and is then suppose to call a BaseAdapter class, create an adapter, and set the a

相关标签:
4条回答
  • 2020-12-02 03:25

    Have you checked if the View v that you return from your getView() method is null? Catching Exception catches all exceptions. Not really helpful in my opinion. What's happening here is that you have not initiated Context ctx_invitation. You should do this in the constructor. Now, since ctx_invitation is null, it causes a NullPointerException which is caught by the catch block. and View v remains null.

    Change the constructor for CreateCommentLists:

    public CreateCommentLists(String[] comments, String[] usernames, String[] numbers, DashboardActivity context)
            {
                super();
    
                listComments = comments;
                listNumbers = usernames;
                listUsernames = numbers;
                ctx_invitation = context;
            }
    

    Change the following as well:

    CreateCommentLists mycmlist = new CreateCommentLists(comments, usernames, numbers, DashboardActivity.this);
    
    0 讨论(0)
  • 2020-12-02 03:27

    Googling around, looking at this question looks like you might be returning a null view from your adapter's getView method. Try tossing some breakpoints into the getView method and figure out where you are returning a null view.

    Also, where are you storing the reference to the ctx_invitation in your BaseAdapter.

    In the constructor you might want to pass that in

    0 讨论(0)
  • 2020-12-02 03:43

    I hope this might be help,

    onPostExecute include (Inside AsyncTask)

    ExampleAdapter sectionedAdapter = new EfficientAdapter(ClassInfoThread.this,getBaseContext()); listView.setAdapter(sectionedAdapter);

    and in your adapter class add this constructor

    public ExampleAdapter(ExampleThread exampleThread,Context context) { mInflater = LayoutInflater.from(context); }

    good luck.

    Nandakishore P

    0 讨论(0)
  • 2020-12-02 03:43

    Now ctx_invitation is never assigned a value. You probably need a constructor to assign value to ctx_invitation.

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