Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project?
Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
While you're at it, check out some resources Treehouse students have shared
here
.
Looking to learn something new?
Treehouse offers a seven day free trial for new students.
Get access to thousands of hours of content and join thousands of
Treehouse students and alumni in the community today.
Start your free trial
i download okHttp-2.3.0.jar from
http://square.github.io/okhttp/
, then i copy and past the jar file to my folder libs in 'src/main/lib, i have update build.gradle(app) with compile fielTree 'src/main/libs', then after i give internet permission, i tried and get fatal exception. can u help u?
Andorid_manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="toma.stormy" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "toma.stormy"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile fileTree('src/main/libs')
MyJava :
package toma.stormy;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import java.io.IOException;
public class MainActivity extends ActionBarActivity {
public static final String TAG = MainActivity.class.getSimpleName();
private OkHttpClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String apiKey = "ff9f25fc6c26897b55bc05fec81093c3";
double latitude = 37.8267;
double longitude = -122.423;
String forecastURL = "https://api.forecast.io/forecast/" + apiKey + "/" + latitude +"," + longitude;
client = new OkHttpClient();
Request request = new Request.Builder().url(forecastURL).build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
@Override
public void onResponse(Response response) throws IOException {
try {
if(response.isSuccessful()){
Log.v(TAG, response.body().string());
} catch (IOException e) {
Log.e(TAG, "Exception caught :", e);
This is mostly a stab in the dark at the moment. I'm not seeing anything that is popping out immediately. Could you remove the file from your libs directory, remove the line compile fileTree('src/main/libs') from your build.gradle file and add in its place compile 'com.squareup.okhttp:okhttp:2.3.0'
Could you also post the full error output to help track this done more?
""ERROR :
1591-1604/toma.stormy E/AndroidRuntime﹕ FATAL EXCEPTION: OkHttp Dispatcher
Process: toma.stormy, PID: 1591
java.lang.NoSuchMethodError: okio.BufferedSource.readHexadecimalUnsignedLong
at com.squareup.okhttp.internal.http.HttpConnection$ChunkedSource.readChunkSize(HttpConnection.java:451)
at com.squareup.okhttp.internal.http.HttpConnection$ChunkedSource.read(HttpConnection.java:432)
at com.squareup.okhttp.internal.Util.skipAll(Util.java:176)
at com.squareup.okhttp.internal.Util.discard(Util.java:158)
at com.squareup.okhttp.internal.http.HttpConnection$ChunkedSource.close(HttpConnection.java:471)
at okio.RealBufferedSource.close(RealBufferedSource.java:252)
at okio.RealBufferedSource.close(RealBufferedSource.java:252)
at okio.InflaterSource.close(InflaterSource.java:121)
at okio.GzipSource.close(GzipSource.java:182)
at okio.RealBufferedSource.close(RealBufferedSource.java:252)
at com.squareup.okhttp.internal.Util.closeQuietly(Util.java:90)
at com.squareup.okhttp.ResponseBody.bytes(ResponseBody.java:59)
at com.squareup.okhttp.ResponseBody.string(ResponseBody.java:83)
at toma.stormy.MainActivity$1.onResponse(MainActivity.java:47)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:168)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
I read on stackoverflow we have to use the 1.0.0 okio lib version, but that doesn't do the trick either. Calling Ben Jakuben for this. I get the FATAL Exception error same as OP but even after adding okio both versions in gradle still doesn't do the trick.
EDIT: scratch that. I was using internet permission instead of PERMISSION. Oh java how sometimes you just want me to punch the screen for a stupid mistake.