Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在异步任务中更改接口(正确的方式)_Java_Android_Json_Android Listview_Android Asynctask - Fatal编程技术网

Java 在异步任务中更改接口(正确的方式)

Java 在异步任务中更改接口(正确的方式),java,android,json,android-listview,android-asynctask,Java,Android,Json,Android Listview,Android Asynctask,我正在尝试将检索到的流程数据更改为列表视图。数据接收正确。但是我没有以正确的方式创建列表视图 这是我的asynctask类 class GetFriendsInfo extends AsyncTask<String, String, String>{ String id = ""; String fullName = ""; String birthday = ""; protected void onPreExecute() {

我正在尝试将检索到的流程数据更改为列表视图。数据接收正确。但是我没有以正确的方式创建列表视图

这是我的asynctask类

class GetFriendsInfo extends AsyncTask<String, String, String>{

    String id = "";
    String fullName = "";
    String birthday = "";

    protected void onPreExecute() {
        super.onPreExecute();
        pd_GetData = new ProgressDialog(MainActivity.this);
        pd_GetData.setMessage("Getting friend data");
        pd_GetData.setIndeterminate(false);
        pd_GetData.setCancelable(true);
        pd_GetData.show();
    }

    @Override
    protected String doInBackground(String... params) {

        JSONArray friendArray;

        List<NameValuePair> param = new ArrayList<NameValuePair>();
        param.add(new BasicNameValuePair("user_id", id));
        param.add(new BasicNameValuePair("user_id", fullName));
        param.add(new BasicNameValuePair("user_id", birthday));

        JSONObject jsonObject = jsonParser.makeHttpRequest(url_get_birthdays,"GET", param);

        try{
            int success = jsonObject.getInt(TAG_SUCCESS);

            if (success == 1){
                Log.d("PHP Server [GET]", "Retrieved user data");

                String jsonString = jsonObject.getString("message");
                friendArray = new JSONArray(jsonString);

                String[] names = new String[friendArray.length()];
                String[] birthdays = new String[friendArray.length()];
                String[] ids = new String[friendArray.length()];

                for(int i=0; i<friendArray.length(); i++) {
                    JSONObject friend = friendArray.getJSONObject(i);
                    String friend_id = friend.getString("id");
                    ids[i] = friend_id;
                    String friend_name = friend.getString("fullName");
                    names[i] = friend_name;
                    String friend_birthday = friend.getString("birthday");
                    birthdays[i] = friend_birthday;
                }

                Log.i("friend:", Arrays.toString(ids) + " " + Arrays.toString(names) + " " + Arrays.toString(birthdays));

               List<HashMap<String, String>> birthday = new ArrayList<HashMap<String, String>>();

                for (int i=0;i<names.length;i++){
                    HashMap<String, String> hm = new HashMap<String, String>();
                    hm.put("names", names[i]);
                    hm.put("ids", ids[i]);
                    hm.put("birthdays", birthdays[i]);
                    birthday.add(hm);
                }

                String[] from = {"names", "ids", "birthdays"};
                int[] to = {R.id.text1, R.id.im_ProfilePic, R.id.text2};

                SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, birthday, R.layout.listitem_birthday, from, to);
                HorizontalListView featuredList = (HorizontalListView) findViewById(R.id.lv_Birthdays);
                featuredList.setAdapter(adapter);

            }else{
                Log.d("PHP Server [GET]", "Failed retrieve user data");
            }
        }catch (JSONException e){
            e.printStackTrace();
        }catch (RuntimeException e){
            e.printStackTrace();
        }

        return null;
    }

    protected void onPostExecute(JSONArray result) {
        // dismiss the dialog once done


        pd_GetData.dismiss();
    }
}
class GetFriendsInfo扩展了异步任务{
字符串id=“”;
字符串fullName=“”;
字符串生日=”;
受保护的void onPreExecute(){
super.onPreExecute();
pd_GetData=new ProgressDialog(MainActivity.this);
pd_GetData.setMessage(“获取好友数据”);
pd_GetData.SetUndeterminate(假);
pd_GetData.setCancelable(真);
pd_GetData.show();
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
JSONArray阵列;
List param=new ArrayList();
参数add(新的BasicNameValuePair(“用户id”,id));
参数add(新的BasicNameValuePair(“用户id”,全名));
参数add(新的BasicNameValuePair(“用户id”,生日));
JSONObject JSONObject=jsonParser.makeHttpRequest(url_get_birthdays,“get”,param);
试一试{
int success=jsonObject.getInt(TAG_success);
如果(成功==1){
d(“PHP服务器[GET],“检索到的用户数据”);
字符串jsonString=jsonObject.getString(“消息”);
friendArray=新的JSONArray(jsonString);
字符串[]名称=新字符串[friendArray.length()];
字符串[]生日=新字符串[friendArray.length()];
String[]ids=新字符串[friendArray.length()];

对于(inti=0;i在onPostExecute()方法中设置适配器

class GetFriendsInfo extends AsyncTask<String, String, String>{

String id = "";
String fullName = "";
String birthday = "";
List<HashMap<String, String>> birthday;

protected void onPreExecute() {
    super.onPreExecute();
    pd_GetData = new ProgressDialog(MainActivity.this);
    pd_GetData.setMessage("Getting friend data");
    pd_GetData.setIndeterminate(false);
    pd_GetData.setCancelable(true);
    pd_GetData.show();
}

@Override
protected String doInBackground(String... params) {

    JSONArray friendArray;

    List<NameValuePair> param = new ArrayList<NameValuePair>();
    param.add(new BasicNameValuePair("user_id", id));
    param.add(new BasicNameValuePair("user_id", fullName));
    param.add(new BasicNameValuePair("user_id", birthday));

    JSONObject jsonObject = jsonParser.makeHttpRequest(url_get_birthdays,"GET", param);

    try{
        int success = jsonObject.getInt(TAG_SUCCESS);

        if (success == 1){
            Log.d("PHP Server [GET]", "Retrieved user data");

            String jsonString = jsonObject.getString("message");
            friendArray = new JSONArray(jsonString);

            String[] names = new String[friendArray.length()];
            String[] birthdays = new String[friendArray.length()];
            String[] ids = new String[friendArray.length()];

            for(int i=0; i<friendArray.length(); i++) {
                JSONObject friend = friendArray.getJSONObject(i);
                String friend_id = friend.getString("id");
                ids[i] = friend_id;
                String friend_name = friend.getString("fullName");
                names[i] = friend_name;
                String friend_birthday = friend.getString("birthday");
                birthdays[i] = friend_birthday;
            }

            Log.i("friend:", Arrays.toString(ids) + " " + Arrays.toString(names) + " " + Arrays.toString(birthdays));

            birthday = new ArrayList<HashMap<String, String>>();

            for (int i=0;i<names.length;i++){
                HashMap<String, String> hm = new HashMap<String, String>();
                hm.put("names", names[i]);
                hm.put("ids", ids[i]);
                hm.put("birthdays", birthdays[i]);
                birthday.add(hm);
            }



        }else{
            Log.d("PHP Server [GET]", "Failed retrieve user data");
        }
    }catch (JSONException e){
        e.printStackTrace();
    }catch (RuntimeException e){
        e.printStackTrace();
    }

    return null;
}

protected void onPostExecute(JSONArray result) {
    // dismiss the dialog once done

    String[] from = {"names", "ids", "birthdays"};
            int[] to = {R.id.text1, R.id.im_ProfilePic, R.id.text2};

            SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, birthday,   R.layout.listitem_birthday, from, to);
            HorizontalListView featuredList = (HorizontalListView) findViewById(R.id.lv_Birthdays);
            featuredList.setAdapter(adapter);

      pd_GetData.dismiss();
  }
}
class GetFriendsInfo扩展了异步任务{
字符串id=“”;
字符串fullName=“”;
字符串生日=”;
列出生日;
受保护的void onPreExecute(){
super.onPreExecute();
pd_GetData=new ProgressDialog(MainActivity.this);
pd_GetData.setMessage(“获取好友数据”);
pd_GetData.SetUndeterminate(假);
pd_GetData.setCancelable(真);
pd_GetData.show();
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
JSONArray阵列;
List param=new ArrayList();
参数add(新的BasicNameValuePair(“用户id”,id));
参数add(新的BasicNameValuePair(“用户id”,全名));
参数add(新的BasicNameValuePair(“用户id”,生日));
JSONObject JSONObject=jsonParser.makeHttpRequest(url_get_birthdays,“get”,param);
试一试{
int success=jsonObject.getInt(TAG_success);
如果(成功==1){
d(“PHP服务器[GET],“检索到的用户数据”);
字符串jsonString=jsonObject.getString(“消息”);
friendArray=新的JSONArray(jsonString);
字符串[]名称=新字符串[friendArray.length()];
字符串[]生日=新字符串[friendArray.length()];
String[]ids=新字符串[friendArray.length()];

对于(inti=0;i在onPostExecute()方法中设置适配器

class GetFriendsInfo extends AsyncTask<String, String, String>{

String id = "";
String fullName = "";
String birthday = "";
List<HashMap<String, String>> birthday;

protected void onPreExecute() {
    super.onPreExecute();
    pd_GetData = new ProgressDialog(MainActivity.this);
    pd_GetData.setMessage("Getting friend data");
    pd_GetData.setIndeterminate(false);
    pd_GetData.setCancelable(true);
    pd_GetData.show();
}

@Override
protected String doInBackground(String... params) {

    JSONArray friendArray;

    List<NameValuePair> param = new ArrayList<NameValuePair>();
    param.add(new BasicNameValuePair("user_id", id));
    param.add(new BasicNameValuePair("user_id", fullName));
    param.add(new BasicNameValuePair("user_id", birthday));

    JSONObject jsonObject = jsonParser.makeHttpRequest(url_get_birthdays,"GET", param);

    try{
        int success = jsonObject.getInt(TAG_SUCCESS);

        if (success == 1){
            Log.d("PHP Server [GET]", "Retrieved user data");

            String jsonString = jsonObject.getString("message");
            friendArray = new JSONArray(jsonString);

            String[] names = new String[friendArray.length()];
            String[] birthdays = new String[friendArray.length()];
            String[] ids = new String[friendArray.length()];

            for(int i=0; i<friendArray.length(); i++) {
                JSONObject friend = friendArray.getJSONObject(i);
                String friend_id = friend.getString("id");
                ids[i] = friend_id;
                String friend_name = friend.getString("fullName");
                names[i] = friend_name;
                String friend_birthday = friend.getString("birthday");
                birthdays[i] = friend_birthday;
            }

            Log.i("friend:", Arrays.toString(ids) + " " + Arrays.toString(names) + " " + Arrays.toString(birthdays));

            birthday = new ArrayList<HashMap<String, String>>();

            for (int i=0;i<names.length;i++){
                HashMap<String, String> hm = new HashMap<String, String>();
                hm.put("names", names[i]);
                hm.put("ids", ids[i]);
                hm.put("birthdays", birthdays[i]);
                birthday.add(hm);
            }



        }else{
            Log.d("PHP Server [GET]", "Failed retrieve user data");
        }
    }catch (JSONException e){
        e.printStackTrace();
    }catch (RuntimeException e){
        e.printStackTrace();
    }

    return null;
}

protected void onPostExecute(JSONArray result) {
    // dismiss the dialog once done

    String[] from = {"names", "ids", "birthdays"};
            int[] to = {R.id.text1, R.id.im_ProfilePic, R.id.text2};

            SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, birthday,   R.layout.listitem_birthday, from, to);
            HorizontalListView featuredList = (HorizontalListView) findViewById(R.id.lv_Birthdays);
            featuredList.setAdapter(adapter);

      pd_GetData.dismiss();
  }
}
class GetFriendsInfo扩展了异步任务{
字符串id=“”;
字符串fullName=“”;
字符串生日=”;
列出生日;
受保护的void onPreExecute(){
super.onPreExecute();
pd_GetData=new ProgressDialog(MainActivity.this);
pd_GetData.setMessage(“获取好友数据”);
pd_GetData.SetUndeterminate(假);
pd_GetData.setCancelable(真);
pd_GetData.show();
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
JSONArray阵列;
List param=new ArrayList();
参数add(新的BasicNameValuePair(“用户id”,id));
参数add(新的BasicNameValuePair(“用户id”,全名));
参数add(新的BasicNameValuePair(“用户id”,生日));
JSONObject JSONObject=jsonParser.makeHttpRequest(url_get_birthdays,“get”,param);
试一试{
int success=jsonObject.getInt(TAG_success);
如果(成功==1){
d(“PHP服务器[GET],“检索到的用户数据”);
字符串jsonString=jsonObject.getString(“消息”);
friendArray=新的JSONArray(jsonString);
字符串[]名称=新字符串[friendArray.length()];
字符串[]生日=新字符串[friendArray.length()];
String[]ids=新字符串[friendArray.length()];

对于(inti=0;i在onPostExecute()方法中设置适配器

class GetFriendsInfo extends AsyncTask<String, String, String>{

String id = "";
String fullName = "";
String birthday = "";
List<HashMap<String, String>> birthday;

protected void onPreExecute() {
    super.onPreExecute();
    pd_GetData = new ProgressDialog(MainActivity.this);
    pd_GetData.setMessage("Getting friend data");
    pd_GetData.setIndeterminate(false);
    pd_GetData.setCancelable(true);
    pd_GetData.show();
}

@Override
protected String doInBackground(String... params) {

    JSONArray friendArray;

    List<NameValuePair> param = new ArrayList<NameValuePair>();
    param.add(new BasicNameValuePair("user_id", id));
    param.add(new BasicNameValuePair("user_id", fullName));
    param.add(new BasicNameValuePair("user_id", birthday));

    JSONObject jsonObject = jsonParser.makeHttpRequest(url_get_birthdays,"GET", param);

    try{
        int success = jsonObject.getInt(TAG_SUCCESS);

        if (success == 1){
            Log.d("PHP Server [GET]", "Retrieved user data");

            String jsonString = jsonObject.getString("message");
            friendArray = new JSONArray(jsonString);

            String[] names = new String[friendArray.length()];
            String[] birthdays = new String[friendArray.length()];
            String[] ids = new String[friendArray.length()];

            for(int i=0; i<friendArray.length(); i++) {
                JSONObject friend = friendArray.getJSONObject(i);
                String friend_id = friend.getString("id");
                ids[i] = friend_id;
                String friend_name = friend.getString("fullName");
                names[i] = friend_name;
                String friend_birthday = friend.getString("birthday");
                birthdays[i] = friend_birthday;
            }

            Log.i("friend:", Arrays.toString(ids) + " " + Arrays.toString(names) + " " + Arrays.toString(birthdays));

            birthday = new ArrayList<HashMap<String, String>>();

            for (int i=0;i<names.length;i++){
                HashMap<String, String> hm = new HashMap<String, String>();
                hm.put("names", names[i]);
                hm.put("ids", ids[i]);
                hm.put("birthdays", birthdays[i]);
                birthday.add(hm);
            }



        }else{
            Log.d("PHP Server [GET]", "Failed retrieve user data");
        }
    }catch (JSONException e){
        e.printStackTrace();
    }catch (RuntimeException e){
        e.printStackTrace();
    }

    return null;
}

protected void onPostExecute(JSONArray result) {
    // dismiss the dialog once done

    String[] from = {"names", "ids", "birthdays"};
            int[] to = {R.id.text1, R.id.im_ProfilePic, R.id.text2};

            SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, birthday,   R.layout.listitem_birthday, from, to);
            HorizontalListView featuredList = (HorizontalListView) findViewById(R.id.lv_Birthdays);
            featuredList.setAdapter(adapter);

      pd_GetData.dismiss();
  }
}
class GetFriendsInfo扩展了异步任务{
字符串id=“”;
字符串fullName=“”;
字符串生日=”;
列出生日;
受保护的void onPreExecute(){
super.onPreExecute();
pd_GetData=new ProgressDialog(MainActivity.this);
pd_GetData.setMessage(“获取好友数据”);
pd_GetData.SetUndeterminate(假);
pd_GetData.setCancelable(真);
pd_GetData.show();
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
JSONArray阵列;
List param=new ArrayList();
参数add(新的BasicNameValuePair(“用户id”,id));
参数add(新的BasicNameValuePair(“用户id”,全名));
参数add(新的BasicNameValuePair(“用户id”,生日));
JSONObject JSONObject=jsonParser.makeHttpRequest(url_get_birthdays,“get”,param);
试一试{
int success=jsonObject.getInt(TAG_success);
如果(成功==1){
d(“PHP服务器[GET],“检索到的用户数据”);
字符串jsonString=jsonObject.getString(“消息”);
friendArray=新的JSONArray(jsonString);
字符串[]名称=新字符串[friendArray.length()];
字符串[]生日=新字符串[friendArray.length()];
String[]ids=新字符串[friendArray.length()];

对于(inti=0;i在onPostExecute()方法中设置适配器

class GetFriendsInfo extends AsyncTask<String, String, String>{

String id = "";
String fullName = "";
String birthday = "";
List<HashMap<String, String>> birthday;

protected void onPreExecute() {
    super.onPreExecute();
    pd_GetData = new ProgressDialog(MainActivity.this);
    pd_GetData.setMessage("Getting friend data");
    pd_GetData.setIndeterminate(false);
    pd_GetData.setCancelable(true);
    pd_GetData.show();
}

@Override
protected String doInBackground(String... params) {

    JSONArray friendArray;

    List<NameValuePair> param = new ArrayList<NameValuePair>();
    param.add(new BasicNameValuePair("user_id", id));
    param.add(new BasicNameValuePair("user_id", fullName));
    param.add(new BasicNameValuePair("user_id", birthday));

    JSONObject jsonObject = jsonParser.makeHttpRequest(url_get_birthdays,"GET", param);

    try{
        int success = jsonObject.getInt(TAG_SUCCESS);

        if (success == 1){
            Log.d("PHP Server [GET]", "Retrieved user data");

            String jsonString = jsonObject.getString("message");
            friendArray = new JSONArray(jsonString);

            String[] names = new String[friendArray.length()];
            String[] birthdays = new String[friendArray.length()];
            String[] ids = new String[friendArray.length()];

            for(int i=0; i<friendArray.length(); i++) {
                JSONObject friend = friendArray.getJSONObject(i);
                String friend_id = friend.getString("id");
                ids[i] = friend_id;
                String friend_name = friend.getString("fullName");
                names[i] = friend_name;
                String friend_birthday = friend.getString("birthday");
                birthdays[i] = friend_birthday;
            }

            Log.i("friend:", Arrays.toString(ids) + " " + Arrays.toString(names) + " " + Arrays.toString(birthdays));

            birthday = new ArrayList<HashMap<String, String>>();

            for (int i=0;i<names.length;i++){
                HashMap<String, String> hm = new HashMap<String, String>();
                hm.put("names", names[i]);
                hm.put("ids", ids[i]);
                hm.put("birthdays", birthdays[i]);
                birthday.add(hm);
            }



        }else{
            Log.d("PHP Server [GET]", "Failed retrieve user data");
        }
    }catch (JSONException e){
        e.printStackTrace();
    }catch (RuntimeException e){
        e.printStackTrace();
    }

    return null;
}

protected void onPostExecute(JSONArray result) {
    // dismiss the dialog once done

    String[] from = {"names", "ids", "birthdays"};
            int[] to = {R.id.text1, R.id.im_ProfilePic, R.id.text2};

            SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, birthday,   R.layout.listitem_birthday, from, to);
            HorizontalListView featuredList = (HorizontalListView) findViewById(R.id.lv_Birthdays);
            featuredList.setAdapter(adapter);

      pd_GetData.dismiss();
  }
}
class GetFriendsInfo扩展了异步任务{
字符串id=“”;
字符串fullName=“”;
字符串生日=”;
列出生日;
受保护的void onPreExecute(){
super.onPreExecute();
pd_GetData=new ProgressDialog(MainActivity.this);
pd_GetData.setMessage(“获取好友数据”);
pd_GetData.SetUndeterminate(假);
pd_GetData.setCancelable(真);
pd_GetData.show();
}
@凌驾
普罗特