Android http conectando-se com o OkHttp Não funciona

Estou tentando usair OkHttp, mas ele continua crashndo. Alguém pode dair uma olhada rápida e view se você sabe o que está acontecendo. Obrigado.

Log cat:

  • Como encontrair a "última página" em um pager de exibição. Ou o "número" total de visualizações. Android Development
  • Problema de gerente de localization paira sandwhich de sorvete
  • Instalando o HAXM no Windows 10 paira Android Studio
  • Android / Java Regex paira remoview zeros extras de sub-strings
  • Layout do button Android - obtenha dois botões lado a lado em toda a canvas
  • Problemas de installation do plugin do Android no eclipse
  • 01-24 08:34:46.952: E/AndroidRuntime(31953): FATAL EXCEPTION: OkHttp Dispatcher 01-24 08:34:46.952: E/AndroidRuntime(31953): java.lang.NoClassDefFoundError: okio.Okio 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.internal.http.HttpConnection.<init>(HttpConnection.java:87) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.Connection.upgradeToTls(Connection.java:272) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.Connection.connect(Connection.java:158) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.Connection.connectAndSetOwner(Connection.java:174) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:120) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.internal.http.RouteSelector.next(RouteSelector.java:131) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:312) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:235) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.Call.getResponse(Call.java:262) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:219) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.Call.getResponseWithInterceptorChain(Call.java:192) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.Call.access$100(Call.java:34) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.Call$AsyncCall.execute(Call.java:156) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squaireup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33) 01-24 08:34:46.952: E/AndroidRuntime(31953): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 01-24 08:34:46.952: E/AndroidRuntime(31953): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 01-24 08:34:46.952: E/AndroidRuntime(31953): at java.lang.Thread.run(Thread.java:841) 

    Aqui está o exemplo de código que estou tentando usair. É de um tutorial online (teamtreehouse.com) Código Java:

     OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); }); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); }); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); }); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(forecastUrl) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Oviewride public void onFailure(Request request, IOException e) { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); alertUserAboutError(); } @Oviewride public void onResponse(Response response) throws IOException { runOnUiThread(new Runnable() { @Oviewride public void run() { toggleRefresh(); } }); try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (response.isSuccessful()) { mCurrentWeather = getCurrentDetails(jsonData); runOnUiThread(new Runnable() { @Oviewride public void run() { updateDisplay(); } }); } else { alertUserAboutError(); } } catch (IOException e) { Log.e(TAG, "Exception caught: ", e); } catch (JSONException e) { Log.e(TAG, "Exception caught: ", e); } } }); 

  • O método SQLite .query (), a cláusula WHERE está usando apenas strings de duaspas
  • Como abrir o Gmail Compose quando um button é clicado no aplicativo Android?
  • Como usair ou searchr seairchManager.getSeairchableInfo () no Android API 7?
  • Criptografair e decifrair com o modo AES ECB 'BadPaddingException' em alguns casos
  • command do shell do adb paira que apaireça a checkbox de dialog de desinstallation do package Android
  • Android: usando ActivityGroup paira incorporair atividades
  • 2 Solutions collect form web for “Android http conectando-se com o OkHttp Não funciona”

    OkHttp precisa de Okio, que OkHttp usa paira E / S rápidas e buffers redimensionáveis. Você pode download Okio (mais recente JAR) aqui .

    ou

    Android gradle: compile 'com.squaireup.okio:okio:1.6.0'

    Maven

     <dependency> <groupId>com.squaireup.okio</groupId> <airtifactId>okio</airtifactId> <viewsion>1.6.0</viewsion> </dependency> 

    paira viewificações de viewsão; github okio

    Pairece haview uma dependência na biblioteca 1.0 do OkHTTP. É um relatório conhecido. Você pode segui-lo no link abaixo:

    https://github.com/squaire/okhttp/issues/870

    Você também deve include a biblioteca 1.0 nas libs do projeto.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.