BaseAdapter class wont setAdapter inside Asynctask - Android

后端 未结 4 552
谎友^
谎友^ 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);
    

提交回复
热议问题