Guest User

Untitled

a guest
Nov 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. @GET("site.get.pagescount.php")
  2. Call<Integer> getCountPages(@Query("token") String token);
  3.  
  4. Retrofit retrofit = new Retrofit.Builder()
  5. .baseUrl(CFG.ENDPOINT)
  6. //.addConverterFactory(GsonConverterFactory.create(gson))
  7. /*код скопипасчен с реализации запроса, который получает JSON*/
  8. .build();
  9. API api = retrofit.create(API.class);
  10. Call<Page> call = api.getCountPages(CFG.TOKEN);
  11. Responce<Integer> b = call.execute();
  12.  
  13. FATAL EXCEPTION: main
  14. Process: ru.idaspin.site, PID: 21496
  15. android.os.NetworkOnMainThreadException
  16. at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
  17. at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
  18. at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
  19. at java.net.InetAddress.getAllByName(InetAddress.java:215)
  20. at okhttp3.Dns$1.lookup(Dns.java:39)
  21. at okhttp3.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:173)
  22. at okhttp3.internal.http.RouteSelector.nextProxy(RouteSelector.java:139)
  23. at okhttp3.internal.http.RouteSelector.next(RouteSelector.java:81)
  24. at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:172)
  25. at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
  26. at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
  27. at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
  28. at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
  29. at okhttp3.RealCall.getResponse(RealCall.java:243)
  30. at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
  31. at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
  32. at okhttp3.RealCall.execute(RealCall.java:57)
  33. at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
  34. at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:89)
  35. at ru.idaspin.site.Fragments.HomeFragment.nextPage(HomeFragment.java:240)
  36. ...
  37.  
  38. Call<ResponseBody> call = api.getInteger(foo);
  39. call.enqueue(new Callback<ResponseBody>() {
  40.  
  41. @Override
  42. public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
  43. int value = Integer.parseInt(response.body().toString());
  44. }
  45.  
  46. @Override
  47. public void onFailure(Call<Integer> call, Throwable t) {
  48. //Do something with failure
  49. }
  50. });
Add Comment
Please, Sign In to add comment