Android : Error with Picasa API JSON request - org.json.JSONException: End of input at character 0 of

on Monday, March 30, 2015


I am trying to GET a JSON response from Picasa API but caught the error:



org.json.JSONException: End of input at character 0 of



Request URL: https://picasaweb.google.com/data/feed/api/user/kodingralph?kind=album&alt=json


My code:



JsonObjectRequest jsonObjReq = new JsonObjectRequest(url, null,
new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "Albums Response: " + response);
List<Category> albums = new ArrayList<Category>();
try {
JSONArray entry = response.getJSONObject(TAG_FEED)
.getJSONArray(TAG_ENTRY);

for (int i = 0; i < entry.length(); i++) {
JSONObject albumObj = (JSONObject) entry.get(i);
String albumId = albumObj.getJSONObject(
TAG_GPHOTO_ID).getString(TAG_T);
String albumTitle = albumObj.getJSONObject(
TAG_ALBUM_TITLE).getString(TAG_T);

Category album = new Category();
album.setId(albumId);
album.setTitle(albumTitle);

albums.add(album);

Log.d(TAG, "Album Id: " + albumId
+ ", Album Title: " + albumTitle);
}

controllerApp.getInstance().getPrefManger()
.storeCategories(albums);

Intent intent = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(intent);
finish();

} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
getString(R.string.msg_unknown_error),
Toast.LENGTH_LONG).show();
}

}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Volley Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
getString(R.string.splash_error),
Toast.LENGTH_LONG).show();
}
});

0 comments:

Post a Comment