JSONException: "end of input at character 0 of"

Forums » Android - Learning Android book > JSONException: "end of input at character 0 of"
November 29, 2011 7:05:44 PM PST (one year ago). Seen 3,630 times. 3 replies.
Photo Brian Cooke
Sr. Analyst, Reporting & Analysis
Verizon Wireless
Member since Nov 29, 2011
Forum Posts: 2
Hello,

First of all, thanks to Marko for the excellent book. Good way for an old Unix command-line programmer like me to get his feet wet with Android, and GUI programming in general.

I've made it to the threaded status update code in example 6-5 (also does this with example 6-3). My app posts to yamba.marakana.com OK (I can see the postings on the website), but I get back a JSONException, presumably a problem parsing the JSON that comes back after posting. In example 6-3 it did a force-close on the app, and in 6-5 it gives a "Failed to post" toast.

Any ideas? The LogCat messages are below:

Code:

11-29 18:51:17.383: E/StatusActivity(310): winterwell.jtwitter.TwitterException: org.json.JSONException: End of input at character 0 of
11-29 18:51:17.383: W/System.err(310): winterwell.jtwitter.TwitterException: org.json.JSONException: End of input at character 0 of
11-29 18:51:17.393: W/System.err(310): at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2584)
11-29 18:51:17.393: W/System.err(310): at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2502)
11-29 18:51:17.393: W/System.err(310): at com.saltedsnail.yamba.StatusActivity$PostToTwitter.doInBackground(StatusActivity.java:43)
11-29 18:51:17.393: W/System.err(310): at com.saltedsnail.yamba.StatusActivity$PostToTwitter.doInBackground(StatusActivity.java:1)
11-29 18:51:17.403: W/System.err(310): at android.os.AsyncTask$2.call(AsyncTask.java:185)
11-29 18:51:17.403: W/System.err(310): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-29 18:51:17.403: W/System.err(310): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-29 18:51:17.403: W/System.err(310): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
11-29 18:51:17.414: W/System.err(310): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
11-29 18:51:17.414: W/System.err(310): at java.lang.Thread.run(Thread.java:1096)
11-29 18:51:17.414: W/System.err(310): Caused by: org.json.JSONException: End of input at character 0 of
11-29 18:51:17.423: W/System.err(310): at org.json.JSONTokener.syntaxError(JSONTokener.java:446)
11-29 18:51:17.423: W/System.err(310): at org.json.JSONTokener.nextValue(JSONTokener.java:93)
11-29 18:51:17.433: W/System.err(310): at org.json.JSONObject.<init>(JSONObject.java:154)
11-29 18:51:17.433: W/System.err(310): at org.json.JSONObject.<init>(JSONObject.java:171)
11-29 18:51:17.433: W/System.err(310): at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2557)
11-29 18:51:17.433: W/System.err(310): ... 9 more
Edited one time. Last edit by Brian Cooke on Nov 29, 2011 at 7:05:44 PM (about one year ago).
November 30, 2011 11:08:01 AM PST (one year ago)
Photo Marko Gargenta
@MarkoGargenta
Marakana, Inc.
Member since Jan 19, 2007
Location: San Francisco
Forum Posts: 227
Hi Brian, huh, I haven't seen this type of error before. And since nothing changed on our server end, I'd imagine it could be something to do with the JTwitter library you are using. Hope that helps!
M...
November 30, 2011 11:15:15 AM PST (one year ago)
Photo Brian Cooke
Sr. Analyst, Reporting & Analysis
Verizon Wireless
Member since Nov 29, 2011
Forum Posts: 2
Marko,

Thanks for the reply. I suspected it was the JTwitter library as well; however, it does this with both the version that came with the book and with the latest version from Winterwell.

I was working on this at the office from behind a proxy server, but when I ran it from my home machine without going through an HTTP proxy, I didn't get this error. So I'm guessing the JSON being returned is getting messed up by our proxy. I will have to dig into the docs to see how best to view that JSON and compare the two versions.

Thanks,

Brian
November 30, 2011 12:14:38 PM PST (one year ago)
Photo Marko Gargenta
@MarkoGargenta
Marakana, Inc.
Member since Jan 19, 2007
Location: San Francisco
Forum Posts: 227
There you go! It's proxy's fault. I like putting blame on proxies :)
Glad it works now.