Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @GET("site.get.pagescount.php")
- Call<Integer> getCountPages(@Query("token") String token);
- Retrofit retrofit = new Retrofit.Builder()
- .baseUrl(CFG.ENDPOINT)
- //.addConverterFactory(GsonConverterFactory.create(gson))
- /*код скопипасчен с реализации запроса, который получает JSON*/
- .build();
- API api = retrofit.create(API.class);
- Call<Page> call = api.getCountPages(CFG.TOKEN);
- Responce<Integer> b = call.execute();
- FATAL EXCEPTION: main
- Process: ru.idaspin.site, PID: 21496
- android.os.NetworkOnMainThreadException
- at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
- at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
- at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
- at java.net.InetAddress.getAllByName(InetAddress.java:215)
- at okhttp3.Dns$1.lookup(Dns.java:39)
- at okhttp3.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:173)
- at okhttp3.internal.http.RouteSelector.nextProxy(RouteSelector.java:139)
- at okhttp3.internal.http.RouteSelector.next(RouteSelector.java:81)
- at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:172)
- at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
- at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
- at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
- at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
- at okhttp3.RealCall.getResponse(RealCall.java:243)
- at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
- at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
- at okhttp3.RealCall.execute(RealCall.java:57)
- at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
- at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:89)
- at ru.idaspin.site.Fragments.HomeFragment.nextPage(HomeFragment.java:240)
- ...
- Call<ResponseBody> call = api.getInteger(foo);
- call.enqueue(new Callback<ResponseBody>() {
- @Override
- public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
- int value = Integer.parseInt(response.body().toString());
- }
- @Override
- public void onFailure(Call<Integer> call, Throwable t) {
- //Do something with failure
- }
- });
Add Comment
Please, Sign In to add comment