view raw
Karim Abd Elhameed Mohamed Karim Abd Elhameed Mohamed - 8 months ago 162
Android Question

Android : Issues with Retrofit 2 and GSON & JSON

I'm now try to parse JSON FROM this link ("")

This is what I do in my Java:

package com.example.karim.bluecrunch;


public class SinglePhotoRetrofit {
public String id;
public String owner;
public String secret;
public String server;
public int farm;

public String title;

public int ispublic;

public int isfriend;

public int isfamily;

public String getTitle() {
return title;

public void setTitle(String title) {
this.title = title;


package com.example.karim.bluecrunch;


import java.util.ArrayList;
import java.util.List;

* Created by karim on 8/26/16.
public class PhotosRetrofit {
public int page;

public int pages;

public int perpage;

public String total;

public List<SinglePhotoRetrofit> photo;

public String stat;

public List<SinglePhotoRetrofit> getPhoto() {
return photo;

public void setPhoto(List<SinglePhotoRetrofit> photo) { = photo;

public String getTotal() {
return total;

public void setTotal(String total) { = total;

and here is my interface

package com.example.karim.bluecrunch;

import java.util.List;

import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;

* Created by karim on 8/26/16.
public interface HandleRetrofit {

Call<PhotosRetrofit> Photos (
@Query("method") String method,
@Query("api_key") String key,
@Query("format") String format,
@Query("nojsoncallback") int call_back,
@Query("auth_token") String token,
@Query("api_sig") String sig

Retrofit retrofit = new Retrofit.Builder()

and my MainActivity looks like

package com.example.karim.bluecrunch;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {

final String API_KEY = "fdac2e9676991ac53b34651adab52518";
final String METHOD = "";
final String AUTH_TOKEN = "72157671978046542-6e266595ffed01f8";
final String API_SIG = "58e08d365779a8f2e946a2b5320199e2";
final String FORMAT = "json";
final int CALL_BACK = 1;

HandleRetrofit handleRetrofit = HandleRetrofit.retrofit.create(HandleRetrofit.class);
Call<PhotosRetrofit> call = handleRetrofit.Photos(METHOD,API_KEY,FORMAT,CALL_BACK,AUTH_TOKEN,API_SIG);
call.enqueue(new Callback<PhotosRetrofit>() {
public void onResponse(Call<PhotosRetrofit> call, Response<PhotosRetrofit> response) {
Log.d("MainActivity", "Status Code = " + response.code());
TextView textView = (TextView) findViewById(;

PhotosRetrofit photosRetrofit = response.body();



public void onFailure(Call<PhotosRetrofit> call, Throwable t) {
Toast.makeText(MainActivity.this,"Error :"+t.getMessage(),Toast.LENGTH_LONG).show();
Log.w("---___--- Error ",t.getMessage());


It returns null in my TextView, also I've tried more and more to retrieve different data but I've failed on that.


Create another one class:

public class Photos{
  public PhotosRetrofit photos;

Update your interface:

 Call<Photos> Photos (...)

Update activity:

Call<Photos> call = handleRetrofit.Photos(METHOD,API_KEY,FORMAT,CALL_BACK,AUTH_TOKEN,API_SIG);
call.enqueue(new Callback<Photos>() {
    public void onResponse(Call<Photos> call, Response<Photos> response) {
        TextView textView = (TextView) findViewById(;
        PhotosRetrofit photosRetrofit = response.body().photos;