J'essaie de communiquer avec le serveur avec Retrofit, mais j'ai toujours une référence nulle.La bibliothèque Android Retrofit renvoie toujours une valeur nulle
L'API: http://gaborbencebekesi.hu/vote/api/get/questions
Dans l'application, j'ai une classe de modèle:
Question public class {
public String question;
public String uploader;
public boolean password;
public String url;
public Question(String question, String uploader, boolean password, String url) {
this.question = question;
this.uploader = uploader;
this.password = password;
this.url = url;
}
}
et une classe de réseau.
réseau public class {
private final String API_URL = "http://gaborbencebekesi.hu/vote/";
private Retrofit retrofit;
private interface Questions {
@GET("api/get/questions/")
Call<List<Question>> get();
}
public Network() {
retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public List<Question> GetQuestions() throws IOException {
// Create an instance of our GitHub API interface.
Questions questions = retrofit.create(Questions.class);
// Create a call instance for looking up Retrofit contributors.
Call<List<Question>> call = questions.get();
// Fetch and print a list of the contributors to the library.
List<Question> q = call.execute().body();
if(q == null) System.err.println("list is null");
return q;
}
}
dernière fonction retourne toujours null.
Est-ce que quelqu'un a une idée pour le résoudre?
Merci!
Qu'est-ce que dans votre fichier Questions.java? (pas Question.java) – ninjayoto