Json BaseAdapter类不工作-Android

Json BaseAdapter类不工作-Android,json,class,android-listview,android-asynctask,baseadapter,Json,Class,Android Listview,Android Asynctask,Baseadapter,我有一个Asynctask,它通过JSON方法收集注释。然后它将注释放入一个字符串[]中,该字符串被放入listView中,问题是扩展BaseAdapter的类给了我一个错误并且不允许我使用它?数字应该是一个字符串!不是整数。这是我当前的代码 class loadComments extends AsyncTask<JSONObject, String, JSONObject> { private ArrayAdapter<String>

我有一个Asynctask,它通过JSON方法收集注释。然后它将注释放入一个字符串[]中,该字符串被放入listView中,问题是扩展BaseAdapter的类给了我一个错误并且不允许我使用它?数字应该是一个字符串!不是整数。这是我当前的代码

    class loadComments extends AsyncTask<JSONObject, String, JSONObject> {
             private ArrayAdapter<String> mAdapter = null;

            @Override
            protected void onPreExecute() {
                super.onPreExecute();


            } 

            @Override
            protected void onProgressUpdate(String... values) {
                super.onProgressUpdate(values);

            } 

            protected JSONObject doInBackground(JSONObject... params) {


                JSONObject json2 = CollectComments.collectComments(usernameforcomments, offsetNumber);


                    return json2;



            }

            @Override
            protected void onPostExecute(JSONObject json2) {
                try {  
                    if (json2.getString(KEY_SUCCESS) != null) { 
                        registerErrorMsg.setText("");
                        String res2 = json2.getString(KEY_SUCCESS);
                        if(Integer.parseInt(res2) == 1){ 
                             l1=(ListView)findViewById(R.id.list);


                            JSONArray commentArray = json2.getJSONArray(KEY_COMMENT);
                            final String comments[] = new String[commentArray.length()];
                            for ( int i=0; i<commentArray.length(); i++ ) {
                                comments[i] = commentArray.getString(i);
                            }
                            JSONArray numberArray = json2.getJSONArray(KEY_NUMBER);
                            String numbers[] = new String[numberArray.length()];
                            for ( int i=0; i<numberArray.length(); i++ ) {
                                numbers[i] = numberArray.getString(i);
                            }
                            JSONArray usernameArray = json2.getJSONArray(KEY_USERNAME);
                            String usernames[] = new String[usernameArray.length()];
                            for ( int i=0; i<usernameArray.length(); i++ ) {
                                usernames[i] = usernameArray.getString(i);
                            }


                            l1.setAdapter(new dataListAdapter(comments,numbers,usernames));


                            class dataListAdapter extends BaseAdapter {
                                String[] Comment, Username, number ;


                                dataListAdapter() {
                                    Comment = null;
                                    Username = null;
                                    number = null;
                                }

                                public dataListAdapter(String[] text, String[] text1,String[] text3) {
                                    Comment = text;
                                    Username = text1;
                                    number = text3;

                                }

                                public int getCount() {
                                    // TODO Auto-generated method stub
                                    return Comment.length;
                                }

                                public Object getItem(int arg0) {
                                    // TODO Auto-generated method stub
                                    return null;
                                }

                                public long getItemId(int position) {
                                    // TODO Auto-generated method stub
                                    return position;
                                }

                                public View getView(int position, View convertView, ViewGroup parent) {

                                    LayoutInflater inflater = getLayoutInflater();
                                    View row;
                                    row = inflater.inflate(R.layout.list_item, parent, false);
                                    TextView listComment, listnumber, listUsername;

                                    listComment = (TextView) row.findViewById(R.id.listComment);
                                    listnumber = (TextView) row.findViewById(R.id.listNumber);
                                    listUsername=(TextView)row.findViewById(R.id.listPostedBy);
                                    listComment.setText(Comment[position]);
                                    listnumber.setText(number[position]);
                                    listUsername.setText(Username[position]);

                                    return (row);
                                }
                            }









                            }//end if key is == 1
                        else{
                            // Error in registration
                            registerErrorMsg.setText(json2.getString(KEY_ERROR_MSG));
                        }//end else
                    }//end if
                } //end try

                catch (JSONException e) { 
                    e.printStackTrace();
                }//end catch    
            }
        }


        new loadComments().execute();

在适配器中,getView、getCount、getItem和getItemId方法之前缺少@Override注释

我建议您将适配器类置于AsyncTask类方法之外。因为你的代码真的不可读。它应该是这样的:

class LoadComments extends AsyncTask<JSONObject, String, JSONObject> {
    // code here
}

class DataListAdapter extends BaseAdapter {
    // code here
}
class LoadComments扩展了异步任务{
//代码在这里
}
类DataListAdapter扩展了BaseAdapter{
//代码在这里
}

类应始终以大写字母开头(LoadComments类无LoadComments),变量应始终以小写字母开头(String name无String name)。也许我不应该在这里写它,但它会对您很有用,使您的代码更易于阅读:)

但它必须位于asynctask内部,因为asynctask是获取字符串的对象?您可以通过构造函数将初始数据(字符串[]注释、用户名、编号)传递给适配器,因此,在异步任务方法中不需要适配器类。如何将数据传递给适配器?
class LoadComments extends AsyncTask<JSONObject, String, JSONObject> {
    // code here
}

class DataListAdapter extends BaseAdapter {
    // code here
}