2016-08-17 6 views
0

Retrofitレスポンスのロギングで私の最初の刺し傷を取っています.OutHttpがRetrofit 2.xのリリースに自動的に含まれていることを理解しています。NoSuchMethodError改訂履歴を記録しようとしています。JSONレスポンス

アクティビティー:

public class MainActivity extends AppCompatActivity { 

private EditText mSearchTerm; 
private Button mRequestButton; 
private String mQuery; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    mSearchTerm = (EditText) findViewById(R.id.ediText_search_term); 
    mRequestButton = (Button) findViewById(R.id.request_button); 
    mRequestButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      mQuery = mSearchTerm.getText().toString(); 
      HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); 
      interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 
      OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); 
      Retrofit retrofit = new Retrofit.Builder() 
        .baseUrl("http://api.flickr.com/services/rest/") 
        .client(client) 
        .addConverterFactory(GsonConverterFactory.create()) 
        .build(); 


      ApiInterface apiInterface = retrofit.create(ApiInterface.class); 
      Call<List<Photo>> call = apiInterface.getPhotos(mQuery); 
      call.enqueue(new Callback<List<Photo>>() { 
       @Override 
       public void onResponse(Call<List<Photo>> call, Response<List<Photo>> response) { 

       } 

       @Override 
       public void onFailure(Call<List<Photo>> call, Throwable t) { 

       } 
      }); 

     } 
    }); 



} 

//Synchronous vs. Asynchronous 
public interface ApiInterface { 
    @GET("?&method=flickr.photos.search&api_key=1c448390199c03a6f2d436c40defd90e&user_id=tccpg288&format=json") // 
    Call<List<Photo>> getPhotos(@Query("q") String photoSearchTerm); 
    } 

    } 

エラー:

java.lang.NoSuchMethodError: No virtual method log(Ljava/lang/String;)V in class Lokhttp3/internal/Platform; or its super classes (declaration of 'okhttp3.internal.Platform' appears in /data/app/com.troychuinard.flickr_test-1/base.apk) 
                      at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:109) 
                      at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:157) 
                      at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:190) 
                      at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163) 
                      at okhttp3.RealCall.access$100(RealCall.java:30) 
                      at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127) 
                      at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
                      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:818) 

Build.Gradle:

dependencies { 

     compile fileTree(dir: 'libs', include: ['*.jar']) 
     testCompile 'junit:junit:4.12' 
     compile 'com.android.support:appcompat-v7:24.1.1' 
     compile 'com.google.code.gson:gson:2.6.2' 
     compile 'com.squareup.retrofit2:retrofit:2.1.0' 
     compile 'com.squareup.retrofit2:converter-gson:2.1.0' 
     compile 'com.squa 

reup.okhttp3:logging-interceptor:3.2.0' 
} 
+1

コードを別のデバイスで実行しましたか。 – hoomi

+0

私はそれにショットを与えます – tccpg288

+0

私は異なるデバイスで同じエラーを受信して​​います – tccpg288

答えて

1

I私は自分のコードを作成して、付属のエラーが発生します

レトロフィット2.1.0が依存していると思いますOkHttp 3.3.0では、同じバージョンのLogging Interceptorを使用してみてください。

'com.squareup.okhttp3:logging-interceptor:3.3.0'をコンパイルするか、 'com.squareup.okhttp3:okhttp:3.4をコンパイルしてみてください。 1 '

関連する問題