Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

android - org.json.JSONException: End of input at character

when I try to get json that doesn't have object, it works fine. but when I try go get json that has an object it's getting error.

Have you got any idea?

protected Void doInBackground(String... params) {

    String url = "http://example.com/adchara1/";
    JSONArray data = null;

    try {
        JSONObject jsonObject = new JSONObject(result);

        MyArrList = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> map;
        data = jsonObject.getJSONArray("countries");
        data = new JSONArray(getJSONUrl(url));
        for (int i = 0; i < data.length(); i++) {
            JSONObject c = data.getJSONObject(i);
            map = new HashMap<String, Object>();

            // Thumbnail Get ImageBitmap To Object
            map.put("photo", (String) c.getString("photo"));
            map.put("ImageThumBitmap",(Bitmap) loadBitmap(c.getString("photo")));

            // Full (for View Popup)
            map.put("frame", (String) c.getString("frame"));

            MyArrList.add(map);
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

error

12-26 11:51:10.352: W/System.err(23284): org.json.JSONException: End of input at character 0 of 
12-26 11:51:10.368: W/System.err(23284):    at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
12-26 11:51:10.368: W/System.err(23284):    at org.json.JSONTokener.nextValue(JSONTokener.java:97)
12-26 11:51:10.368: W/System.err(23284):    at org.json.JSONObject.<init>(JSONObject.java:154)
12-26 11:51:10.368: W/System.err(23284):    at org.json.JSONObject.<init>(JSONObject.java:171)
12-26 11:51:10.376: W/System.err(23284):    at com.example.gridview.MainActivity$DownloadJSONFileAsync.doInBackground(MainActivity.java:180)
12-26 11:51:10.376: W/System.err(23284):    at com.example.gridview.MainActivity$DownloadJSONFileAsync.doInBackground(MainActivity.java:1)
12-26 11:51:10.376: W/System.err(23284):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-26 11:51:10.376: W/System.err(23284):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-26 11:51:10.376: W/System.err(23284):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-26 11:51:10.376: W/System.err(23284):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-26 11:51:10.376: W/System.err(23284):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-26 11:51:10.376: W/System.err(23284):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-26 11:51:10.376: W/System.err(23284):    at java.lang.Thread.run(Thread.java:856)
12-26 11:51:10.399: D/libEGL(23284): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
12-26 11:51:10.423: D/libEGL(23284): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
12-26 11:51:10.430: D/libEGL(23284): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
12-26 11:51:10.516: D/OpenGLRenderer(23284): Enabling debug mode 0
12-26 11:51:10.735: D/AndroidRuntime(23284): Shutting down VM
12-26 11:51:10.735: W/dalvikvm(23284): threadid=1: thread exiting with uncaught exception (group=0x4158f300)
12-26 11:51:10.735: E/AndroidRuntime(23284): FATAL EXCEPTION: main
12-26 11:51:10.735: E/AndroidRuntime(23284): java.lang.NullPointerException
12-26 11:51:10.735: E/AndroidRuntime(23284):    at com.example.gridview.MainActivity$ImageAdapter.getCount(MainActivity.java:122)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at android.widget.GridView.setAdapter(GridView.java:182)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at com.example.gridview.MainActivity.ShowAllContent(MainActivity.java:91)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at com.example.gridview.MainActivity$DownloadJSONFileAsync.onPostExecute(MainActivity.java:209)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at com.example.gridview.MainActivity$DownloadJSONFileAsync.onPostExecute(MainActivity.java:1)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at android.os.AsyncTask.finish(AsyncTask.java:631)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at android.os.Looper.loop(Looper.java:137)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at android.app.ActivityThread.main(ActivityThread.java:4931)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at java.lang.reflect.Method.invokeNative(Native Method)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at java.lang.reflect.Method.invoke(Method.java:511)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
12-26 11:51:10.735: E/AndroidRuntime(23284):    at dalvik.system.NativeStart.main(Native Method)
12-26 11:51:12.509: I/Process(23284): Sending signal. PID: 23284 SIG: 9
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Change

 JSONObject jsonObject = new JSONObject(result);

to

result=getJSONUrl(url);  //<< get json string from server
JSONObject jsonObject = new JSONObject(result);

inside doInBackground method of DownloadJSONFileAsync because currently you are not making any post for getting Json data from the server and just trying to parse an empty string to json


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...