compiler errors - OkHttp Request is not public in com.squareup.okhttp; cannot be accessed from outside package -
i'm trying okhttp work in android studio project, created class , pasted in following code here: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/com/squareup/okhttp/recipes/parseresponsewithgson.java
package com.my.project; /** * created me on 07/08/2015. */ import com.google.gson.gson; import com.squareup.okhttp.okhttpclient; import com.squareup.okhttp.request; import com.squareup.okhttp.response; import java.io.ioexception; import java.util.map; public final class parseresponsewithgson { private final okhttpclient client = new okhttpclient(); private final gson gson = new gson(); public void run() throws exception { request request = new request.builder() .url("https://api.github.com/gists/c2a7c39532239ff261be") .build(); response response = client.newcall(request).execute(); if (!response.issuccessful()) throw new ioexception("unexpected code " + response); gist gist = gson.fromjson(response.body().charstream(), gist.class); (map.entry<string, gistfile> entry : gist.files.entryset()) { system.out.println(entry.getkey()); system.out.println(entry.getvalue().content); } } static class gist { map<string, gistfile> files; } static class gistfile { string content; } public static void main(string... args) throws exception { new parseresponsewithgson().run(); } }
here's gradle file:
apply plugin: 'com.android.application' repositories { jcenter() flatdir { dirs 'prebuilt-libs' } } android { compilesdkversion "google inc.:glass development kit preview:19" buildtoolsversion "22.0.1" defaultconfig { applicationid "com.my.project_02" minsdkversion 19 targetsdkversion 22 versioncode 2 versionname "0.2" } compileoptions { sourcecompatibility javaversion.version_1_7 targetcompatibility javaversion.version_1_7 } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile filetree(include: ['*.jar'], dir: 'libs') compile 'com.google.code.gson:gson:2.3.1' compile 'com.squareup.okio:okio:1.5.0' compile 'com.squareup.okhttp:okhttp:2.4.0' compile files('libs/glassvoice-xe22.jar') }
but errors "error:(8, 27) error: request not public in com.squareup.okhttp; cannot accessed outside package" , "error:(9, 27) error: response not public in com.squareup.okhttp; cannot accessed outside package" occur in parseresponsewithgson class code:
import com.squareup.okhttp.request; import com.squareup.okhttp.response;
does have idea how can fix these errors? seems constructor isn't public sounds strange i've copied , pasted code i'm not sure have done wrong, unless wrong version of okhttp , okio somehow being referenced?
you have another, obsolete, version of okhttp on classpath. old version’s request wasn't public, 1 in 2.0+ is.
try using jar tvf libs/foo.jar
each jar in libs directory find it!
Comments
Post a Comment