Hello, I am learning to use Retrofit . I use AIDE, in jarnik. It is necessary to get a response from the server without passing the parameters to it.

Link: http://chat.pareto-marketing.ru/getform.php

Created a class

 public class App63 extends Application { private static Api63 api63; private Retrofit retrofit; @Override public void onCreate() { super.onCreate(); retrofit = new Retrofit.Builder().baseUrl("http://www.chat.pareto-marketing.ru/").addConverterFactory(GsonConverterFactory.create()).build(); api63 = retrofit.create(Api63.class); } public static Api63 getApi() { return api63; } } 

Interface

 public interface Api63 { @GET("getform") Call<ResponseBody> getData(); } 

A piece of activity code

 Call<ResponseBody> list = App63.getApi().getData(); list.enqueue(new Callback<ResponseBody>() { @Override public void onResponse(Call<ResponseBody> p1, Response<ResponseBody> p2) { try { Log.d("$", p2.body().string()); } catch (IOException e) {} } @Override public void onFailure(Call<ResponseBody> p1, Throwable p2) { // TODO: Implement this method } }); } } 

The resolution in the manifest is. Android 6.0.1

I receive, His Majesty, NPE:

 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String okhttp3.ResponseBody.string()' on a null object reference 

The latest versions of Liby, unite everything into one jar. body.code() returns 404 , body.message() returns Not Found .

  • one
    Well, the link http://www.chat.pareto-marketing.ru/getform/ you have json and is not given - rjhdby
  • Ahahahaha, thanks, here I am an idiot)) - Flippy
  • one
    Oh yes okay, it happens :) - rjhdby

1 answer 1

 public interface Api63 { @GET("getform.php") Call<ResponseBody> getData(); } 

Add .php

  • Thank! Such nonsense, just in the examples there was nowhere . Php - Flippy
  • @Flippy by the way, once they took up the retrofit, I recommend trying it in conjunction with RxJava - a bomb in general - rjhdby
  • I will try, thanks for the idea :) - Flippy