尝试调用虚方法&org.json.JSONArray org.json.JSONObject.getJSONArray(java.lang.String)

时间:2017-08-21 15:13:04

标签: android ip

我有2个同样错误的课程,你能告诉我它有什么问题吗,我使用了本地ip adrees。它是10.0.2.2 这是我的doInBackgroundclass

String url_param;
        url_param = "http://10.0.2.2/webservice/android.php?pl=info";

        JSONParser jParser = new JSONParser();
        JSONObject json = jParser.getJSONFromUrl(url + url_param);
        Log.d("log", "url:" + url + url_param);
        try {
            JSONArray result = json.getJSONArray("result");
            for (int i = 0; i < result.length(); i++) {

                JSONObject c = result.getJSONObject(i);
                String id = c.getString("id");
                String nama = c.getString("nama");
                String info = c.getString("info");
                String tanggal = c.getString("tanggal");

                HashMap<String, String> map = new HashMap<String, String>();

                map.put(in_id, id);
                map.put(in_nama, nama);
                map.put(in_info, info);
                map.put(in_tanggal, tanggal);
                resultList.add(map);
            }
            Log.d("log", "bla:" + resultList);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

这是log cat,所以起初我认为它来自ip地址,但我不确定,我把这个服务器放在localhost上

FATAL EXCEPTION: AsyncTask #1
                                                                     java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                         at android.os.AsyncTask$3.done(AsyncTask.java:309)
                                                                         at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                         at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                         at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                         at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                                         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                         at java.lang.Thread.run(Thread.java:818)
                                                                      Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONArray org.json.JSONObject.getJSONArray(java.lang.String)' on a null object reference

0 个答案:

没有答案