Note that there are some explanatory texts on larger screens.

plurals
  1. POError parsing JSON
    primarykey
    data
    text
    <p>I'm working with Volley and org.json to pull a JSON from a users timeline in twitter. I received a "Error with Request" from my onErrorResponse. It doesn't seem to be a URL problem because I see the desired JSON in the LogCat. Here's the error log:</p> <pre><code>11-30 22:54:52.273: W/TweetLoader(18610): Error with request 11-30 22:54:52.273: W/System.err(18610): com.android.volley.ParseError: org.json.JSONException: Value [{"contributors":null,"text":"18-propeller copter might be the future of personal air travel, inventors say.\nhttp:\/\/t.co\/TMUtbF80Kp via @CNNTech","geo":null,"retweeted":false,"in_reply_to_screen_name":null,"possibly_sensitive":false,"truncated":false,"lang":"en","entities":{"urls":[{"display_url":"cnn.it\/1bWid4q","expanded_url":"http:\/\/cnn.it\/1bWid4q","indices":[79,101],"url":"http:\/\/t.co\/TMUtbF80Kp"}],"hashtags":[],"user_mentions":[{"id":42703075,"indices":[106,114],"screen_name":"cnntech","id_str":"42703075","name":"cnntech"}],"symbols":[]},"in_reply_to_status_id_str":null,"id":406951229278146560,"in_reply_to_user_id_str":null,"source":"&lt;a href=\"http:\/\/www.hootsuite.com\" rel=\"nofollow\"&gt;HootSuite&lt;\/a&gt;","favorited":false,"in_reply_to_status_id":null,"retweet_count":112,"in_reply_to_user_id":null,"created_at":"Sun Dec 01 01:01:48 +0000 2013","favorite_count":59,"id_str":"406951229278146560","place":null,"user":{"location":"","default_profile":false,"profile_background_tile":false,"statuses_count":36621,"lang":"en","profile_link_color":"004287","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/759251\/1384971184","id":759251,"following":null,"favourites_count":4,"protected":false,"profile_text_color":"000000","contributors_enabled":false,"verified":true,"description":"Bringing you breaking news and the most talked about stories. Join the conversation and let’s connect!","profile_sidebar_border_color":"000000","name":"CNN","profile_background_color":"323232","created_at":"Fri Feb 09 00:35:02 +0000 2007","default_profile_image":false,"followers_count":11060197,"profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/378800000049679889\/9097753c470683f49aa12a6c15eba5c7_normal.jpeg","geo_enabled":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/664730338\/60cc7d1f1b1a22a87ccccef026e15949.gif","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/664730338\/60cc7d1f1b1a22a87ccccef026e15949.gif","follow_request_sent":null,"entities":{"description":{"urls":[]},"url":{"urls":[{"display_url":"cnn.com","expanded_url":"http:\/\/www.cnn.com","indices":[0,22],"url":"http:\/\/t.co\/Db6JkaxJ9R"}]}},"url":"http:\/\/t.co\/Db6JkaxJ9R","utc_offset":-18000,"time_zone":"Eastern Time (US &amp; Canada)","notifications":null,"profile_use_background_image":true,"friends_count":818,"profile_sidebar_fill_color":"EEEEEE","screen_name":"CNN","id_str":"759251","profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/378800000049679889\/9097753c470683f49aa12a6c15eba5c7_normal.jpeg","is_translator":false,"listed_count":88693},"coordinates":null},{"contributors":null,"text":"Will online classes make professors extinct? \nhttp:\/\/t.co\/g20MbYagb9 via @CNNOpinion","geo":null,"retweeted":false,"in_reply_to_screen_name":null,"possibly_sensitive":false,"truncated":false,"lang":"en","entities":{"urls":[{"display_url":"cnn.it\/1b4VUbw","expanded_url":"http:\/\/cnn.it\/1b4VUbw","indices":[46,68],"url":"http:\/\/t.co\/g20MbYagb9"}],"hashtags":[],"user_mentions":[{"id":259074538,"indices":[73,84],"screen_name":"CNNOpinion","id_str":"259074538","name":"CNN Opinion"}],"symbols":[]},"in_reply_to_status_id_str":null,"id":406921147427852288,"in_reply_to_user_id_str":null,"source":"&lt;a href=\"http:\/\/www.hootsuite.com\" rel=\"nofollow\"&gt;HootSuite&lt;\/a&gt;","favorited":false,"in_reply_to_status_id":null,"retweet_count":186,"in_reply_to_user_id":null,"created_at":"Sat Nov 30 23:02:16 +0000 2013","favorite_count":98,"id_str":"406921147427852288","place":null,"user":{"location":"","default_profile":false,"profile_background_tile":false,"statuses_count":36621,"lang":"en","profile_link_color":"004287","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/759251\/1384971184","id":759251,"following":null,"favourites_count":4,"protected":false,"profile_text_color":"000000","contributors_enabled":false,"verified":true,"description":"Bringing you breaking news and t 11-30 22:54:52.273: W/System.err(18610): at com.android.volley.toolbox.JsonObjectRequest.parseNetworkResponse(JsonObjectRequest.java:73) 11-30 22:54:52.273: W/System.err(18610): at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:116) 11-30 22:54:52.293: W/System.err(18610): Caused by: org.json.JSONException: Value [{"contributors":null,"text":"18-propeller copter might be the future of personal air travel, inventors say.\nhttp:\/\/t.co\/TMUtbF80Kp via @CNNTech","geo":null,"retweeted":false,"in_reply_to_screen_name":null,"possibly_sensitive":false,"truncated":false,"lang":"en","entities":{"urls":[{"display_url":"cnn.it\/1bWid4q","expanded_url":"http:\/\/cnn.it\/1bWid4q","indices":[79,101],"url":"http:\/\/t.co\/TMUtbF80Kp"}],"hashtags":[],"user_mentions":[{"id":42703075,"indices":[106,114],"screen_name":"cnntech","id_str":"42703075","name":"cnntech"}],"symbols":[]},"in_reply_to_status_id_str":null,"id":406951229278146560,"in_reply_to_user_id_str":null,"source":"&lt;a href=\"http:\/\/www.hootsuite.com\" rel=\"nofollow\"&gt;HootSuite&lt;\/a&gt;","favorited":false,"in_reply_to_status_id":null,"retweet_count":112,"in_reply_to_user_id":null,"created_at":"Sun Dec 01 01:01:48 +0000 2013","favorite_count":59,"id_str":"406951229278146560","place":null,"user":{"location":"","default_profile":false,"profile_background_tile":false,"statuses_count":36621,"lang":"en","profile_link_color":"004287","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/759251\/1384971184","id":759251,"following":null,"favourites_count":4,"protected":false,"profile_text_color":"000000","contributors_enabled":false,"verified":true,"description":"Bringing you breaking news and the most talked about stories. Join the conversation and let’s connect!","profile_sidebar_border_color":"000000","name":"CNN","profile_background_color":"323232","created_at":"Fri Feb 09 00:35:02 +0000 2007","default_profile_image":false,"followers_count":11060197,"profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/378800000049679889\/9097753c470683f49aa12a6c15eba5c7_normal.jpeg","geo_enabled":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/664730338\/60cc7d1f1b1a22a87ccccef026e15949.gif","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/664730338\/60cc7d1f1b1a22a87ccccef026e15949.gif","follow_request_sent":null,"entities":{"description":{"urls":[]},"url":{"urls":[{"display_url":"cnn.com","expanded_url":"http:\/\/www.cnn.com","indices":[0,22],"url":"http:\/\/t.co\/Db6JkaxJ9R"}]}},"url":"http:\/\/t.co\/Db6JkaxJ9R","utc_offset":-18000,"time_zone":"Eastern Time (US &amp; Canada)","notifications":null,"profile_use_background_image":true,"friends_count":818,"profile_sidebar_fill_color":"EEEEEE","screen_name":"CNN","id_str":"759251","profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/378800000049679889\/9097753c470683f49aa12a6c15eba5c7_normal.jpeg","is_translator":false,"listed_count":88693},"coordinates":null},{"contributors":null,"text":"Will online classes make professors extinct? \nhttp:\/\/t.co\/g20MbYagb9 via @CNNOpinion","geo":null,"retweeted":false,"in_reply_to_screen_name":null,"possibly_sensitive":false,"truncated":false,"lang":"en","entities":{"urls":[{"display_url":"cnn.it\/1b4VUbw","expanded_url":"http:\/\/cnn.it\/1b4VUbw","indices":[46,68],"url":"http:\/\/t.co\/g20MbYagb9"}],"hashtags":[],"user_mentions":[{"id":259074538,"indices":[73,84],"screen_name":"CNNOpinion","id_str":"259074538","name":"CNN Opinion"}],"symbols":[]},"in_reply_to_status_id_str":null,"id":406921147427852288,"in_reply_to_user_id_str":null,"source":"&lt;a href=\"http:\/\/www.hootsuite.com\" rel=\"nofollow\"&gt;HootSuite&lt;\/a&gt;","favorited":false,"in_reply_to_status_id":null,"retweet_count":186,"in_reply_to_user_id":null,"created_at":"Sat Nov 30 23:02:16 +0000 2013","favorite_count":98,"id_str":"406921147427852288","place":null,"user":{"location":"","default_profile":false,"profile_background_tile":false,"statuses_count":36621,"lang":"en","profile_link_color":"004287","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/759251\/1384971184","id":759251,"following":null,"favourites_count":4,"protected":false,"profile_text_color":"000000","contributors_enabled":false,"verified":true,"description":"Bringing you breaking news and the most talked about 11-30 22:54:52.293: W/System.err(18610): at org.json.JSON.typeMismatch(JSON.java:111) 11-30 22:54:52.293: W/System.err(18610): at org.json.JSONObject.&lt;init&gt;(JSONObject.java:158) 11-30 22:54:52.293: W/System.err(18610): at org.json.JSONObject.&lt;init&gt;(JSONObject.java:171) 11-30 22:54:52.293: W/System.err(18610): at com.android.volley.toolbox.JsonObjectRequest.parseNetworkResponse(JsonObjectRequest.java:68) 11-30 22:54:52.293: W/System.err(18610): ... 1 more 11-30 22:56:51.289: W/IInputConnectionWrapper(18610): setComposingText on inactive InputConnection </code></pre> <p>Here is the java files.</p> <p>UPDATED TweetRequest.java</p> <pre><code>public class TweetsRequest extends JsonArrayRequest { public TweetsRequest(String url, Listener&lt;JSONArray&gt; listener, ErrorListener errorListener, List&lt;NameValuePair&gt; params) { super(url + "?" + URLEncodedUtils.format(params, "UTF-8"), listener, errorListener); } @Override public Map&lt;String, String&gt; getHeaders() throws AuthFailureError { Map&lt;String, String&gt; headers = new HashMap&lt;String, String&gt;(); String auth = "Bearer " + TwitterValues.ACCESS_TOKEN; headers.put("Authorization", auth); return headers; } } </code></pre> <p>UPDATED TweetLoader.java</p> <pre><code>public class TweetLoader implements OnEndReachedListener { private static final String LIST_URL = "https://api.twitter.com/1.1/statuses/user_timeline.json"; protected static final String TAG = TweetLoader.class.getSimpleName(); private ArrayAdapter&lt;JSONObject&gt; tweetAdapter; private TweetJsonListener mDownListener = new TweetJsonListener(); private String query = "cnn"; private Activity activity; public TweetLoader(ArrayAdapter&lt;JSONObject&gt; tweetAdapter, Activity activity) { this.tweetAdapter = tweetAdapter; this.activity = activity; } public void setQuery(String query) { tweetAdapter.clear(); this.query = query; onEndReached(); } @Override public void onEndReached() { activity.setProgressBarIndeterminate(true); activity.setProgressBarIndeterminateVisibility(true); List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("screen_name", "cnn")); MainActivity.mRequestQueue.add(new TweetsRequest(LIST_URL, mDownListener, new ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.w(TAG, "Error with request"); error.printStackTrace(); } }, params)); } private class TweetJsonListener implements Listener&lt;JSONArray&gt; { public void onResponse(JSONObject response) { JSONObject jsonObject = null; JSONArray tweets = response.optJSONArray("statuses"); int count = tweets != null ? tweets.length() : 0; for (int i = 0; i &lt; count; i++) { jsonObject = tweets.optJSONObject(i); if (jsonObject != null) { tweetAdapter.add(jsonObject); } } activity.setProgressBarIndeterminateVisibility(false); } @Override public void onResponse(JSONArray arg0) { // TODO Auto-generated method stub } } } </code></pre> <p>TweetAdapter.java</p> <pre><code>public class TweetAdapter extends ArrayAdapter&lt;JSONObject&gt; { private static final String TAG = TweetAdapter.class.getSimpleName(); public TweetAdapter(Context context) { super(context, 0); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.twitter_item, null); holder = new ViewHolder(); holder.imageView = (NetworkImageView) convertView.findViewById(R.id.profile_image); holder.nameView = (TextView) convertView.findViewById(R.id.name); holder.textView = (TextView) convertView.findViewById(R.id.text); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } JSONObject currentItem = getItem(position); if (currentItem.length() == 0) { holder.nameView.setText(R.string.loading); holder.textView.setText(""); holder.imageView.setImageResource(R.drawable.ic_launcher); } else { try { JSONObject user = currentItem.getJSONObject("user"); holder.nameView.setText(user.optString("name", "&lt;No name&gt;")); holder.imageView.setImageUrl(user.getString("profile_image_url"), MainActivity.mImageLoader); } catch (JSONException e) { e.printStackTrace(); } holder.textView.setText(currentItem.optString("text", "&lt;No text&gt;")); } return convertView; } private static class ViewHolder { private NetworkImageView imageView; private TextView nameView; private TextView textView; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload