错误java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'int java.lang.String.length()'

时间:2018-09-04 01:23:35

标签: android

我试图解决我的问题,但是我无法解决,仍然在下面的错误代码中:

 private void callVolley(){
        itemList.clear();
        adapter.notifyDataSetChanged();
        swipe.setRefreshing(true);
        postToServer = new PostToServer();
        postToServer.delegate = this;
        postToServer.execute(url_select,
                session.getLocalSession(LocalSession.KEY_USERNAME)
        );
        //String user =session.getLocalSession(LocalSession.KEY_USERNAME);
        //start
        JSONObject jsonObject = null;
        ArrayList<HashMap<String,String>> listview = new ArrayList<HashMap<String, String>>();
        try {
            jsonObject = new JSONObject(JSON_STRING);
            JSONArray result = jsonObject.getJSONArray(TAG_JSON_ARRAY);
            if (result != null) {
                for (int i = 0; i < result.length(); i++) {
                    JSONObject jo = result.getJSONObject(i);
                    String IDPEL = jo.getString(TAG_ID);
                    String NAMA = jo.getString(TAG_NAMA);
                    String ALAMAT = jo.getString(TAG_ALAMAT);

                    HashMap<String, String> employees = new HashMap<>();
                    employees.put(TAG_ID, IDPEL);
                    employees.put(TAG_NAMA, NAMA);
                    employees.put(TAG_ALAMAT, ALAMAT);
                    listview.add(employees);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        ListAdapter adapter = new SimpleAdapter(
                MainActivity.this, listview, R.layout.list_row,
                new String[]{TAG_ID,TAG_NAMA,TAG_ALAMAT},
                new int[]{R.id.id,R.id.nama,R.id.alamat});

        list.setAdapter(adapter);
    }

有人可以帮助我解决我的问题吗?

logcat是

  

Blockquote   09-04 08:07:06.023 26362-26362 / com.mobile.lunatique.myapplication E / AndroidRuntime:FATAL EXCEPTION:main                                                                                       流程:com.mobile.lunatique.myapplication,PID:26362                                                                                       java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'int java.lang.String.length()'                                                                                           在org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)                                                                                           在org.json.JSONTokener.nextValue(JSONTokener.java:94)                                                                                           在org.json.JSONObject。(JSONObject.java:156)                                                                                           在org.json.JSONObject。处(JSONObject.java:173)                                                                                           在com.mobile.lunatique.myapplication.MainActivity.callVolley(MainActivity.java:346)                                                                                           在com.mobile.lunatique.myapplication.MainActivity.access $ 000(MainActivity.java:44)                                                                                           在com.mobile.lunatique.myapplication.MainActivity $ 1.run(MainActivity.java:129)                                                                                           在android.os.Handler.handleCallback(Handler.java:739)                                                                                           在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                           在android.os.Looper.loop(Looper.java:148)                                                                                           在android.app.ActivityThread.main(ActivityThread.java:7406)                                                                                           在java.lang.reflect.Method.invoke(本机方法)                                                                                           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230)                                                                                           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

0 个答案:

没有答案