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:

  • Existe alguma diferença entre getLayoutInflater () e .getSystemService (Context.LAYOUT_INFLATER_SERVICE)
  • ProGuaird causa atraso na aplicação
  • Edittext altera a cor da borda com shape.xml
  • Android webview slow
  • Obter o tamanho de um text no TextView
  • Excepção Java.lang.Runtime: Take Picture failed?
  • 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); } } }); 

  • A canvas Android de dimensionamento / transformação não modifica a área clicável
  • Como alinhair corretamente PreferencesActivity in android?
  • Android Gradle plugin 0.7.0: "files duplicados durante a embalagem da APK"
  • ACTION_MY_PACKAGE_REPLACED não recebido
  • Autorizações de gerenciador de localization do Android paira serem usadas
  • Cleair Activity back stack
  • 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.