2016-08-15 3 views
1

ネットワークコールにretrofit2を使用し、XMLを解析するコンバータとしてretrofit2 converter-simplexmlを使用しています。 ニュースサイト:http://www.cbc.ca/cmlink/rss-topstories/ RSSフィードがあります。エラーを修正することはできません。Retrofit2 converter-simplexmlの "java.lang.IllegalArgumentException:java.util.Listのコンバーターを作成できません"をデバッグするには?

java.lang.IllegalArgumentException: Unable to create converter for java.util.List<com.ku4irka.rss_nfr.model.entity.Channel> 
                    for method ChannelService.getChannel 
                    at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:720) 
                    at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:706) 
                    at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:167) 
                    at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166) 
                    at retrofit2.Retrofit$1.invoke(Retrofit.java:145) 
                    at java.lang.reflect.Proxy.invoke(Proxy.java:397) 
                    at $Proxy0.getChannel(Unknown Source) 
                    at com.ku4irka.rss_nfr.view.activity.ListNewsActivity.configRest(ListNewsActivity.java:48) 
                    at com.ku4irka.rss_nfr.view.activity.ListNewsActivity.onCreate(ListNewsActivity.java:36) 
                    at android.app.Activity.performCreate(Activity.java:5958) 
                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) 
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 
                     ... 10 more 
                    Caused by: java.lang.IllegalArgumentException: Could not locate ResponseBody converter for java.util.List<com.ku4irka.rss_nfr.model.entity.Channel>. 
                    Tried: 
                    * retrofit2.BuiltInConverters 
                    * retrofit2.converter.simplexml.SimpleXmlConverterFactory 
                    at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:346) 
                    at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:308) 
                    at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:704) 
                     ... 20 more 

例コード:

RestManager:

public class RestManager { 

private static final OkHttpClient CLIENT = new OkHttpClient(); 

private static Retrofit retrofit; 

private static ChannelService sChannelService; 

private static void retrofitSetup() { 
    // Retrofit setup 
    retrofit = new Retrofit.Builder() 
      .baseUrl(Constans.HTTP.BASE_URL) 
      .addConverterFactory(SimpleXmlConverterFactory.create()) 
      .client(CLIENT) 
      .build(); 
} 


public static ChannelService getChannelService() { 
    if (sChannelService == null) { 

     retrofitSetup(); 
     // Service setup 
     sChannelService = retrofit.create(ChannelService.class); 
    } 
    return sChannelService; 
} 
} 

サービス:

public interface ChannelService { 
@GET("cmlink/rss-topstories/") 
Call<List<Channel>> getChannel(); 
} 

クラスチャンネル:

@Root(name = "channel") 
public class Channel { 

@Element(name = "guid") 
private double id; 

@Element(name = "title") 
private String title; 

@Element(name = "pubDate") 
private String pubDate; 

@Element(name = "author") 
private String author; 

@Element(name = "description") 
private String description; 

@Element(name = "link") 
private String link; 

public Channel() { 
} 

方法:

private void configRest() { 
    Call<List<Channel>> call = mRestManager.getChannelService().getChannel(); 
    call.enqueue(new Callback<List<Channel>>() { 
     @Override 
     public void onResponse(Call<List<Channel>> call, Response<List<Channel>> response) { 

      if (response.isSuccessful()) { 
       mNewsList = response.body(); 
       setRecyclerView(); 
      } 
     } 
     @Override 
     public void onFailure(Call<List<Channel>> call, Throwable t) { 
      // 
     } 
    }); 
} 

のGradle:

configurations { 
    compile.exclude group: 'stax' 
    compile.exclude group: 'xpp3' 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:24.1.1' 
    compile 'com.android.support:design:24.1.1' 

    compile 'com.android.support:recyclerview-v7:24.1.1' 

    compile 'com.squareup.retrofit2:retrofit:2.1.0' 
    compile 'com.squareup.retrofit2:converter-simplexml:2.1.0' 
    compile 'com.squareup.picasso:picasso:2.5.2' 
    compile 'com.squareup.okhttp3:okhttp:3.3.1' 
compile 'org.simpleframework:simple-xml:2.7.1' 

} 

は問題が何であるかを教えてください?

+0

のバージョンとコンバータの間違ったバージョンを使用していますか? –

+0

[this](/ questions/32343183/retrofit-could-not-locate-converter-for-class-crashing-app)を見ましたか? – Tibrogargan

答えて

0

あなたはおそらく、あなたが改修やSimpleXmlConverterのバージョンを確認することができますレトロフィット

compile 'com.squareup.retrofit2:retrofit:2.1.0' 
compile 'com.squareup.okhttp3:okhttp:3.4.0' 
compile ('com.squareup.retrofit2:converter-simplexml:2.1.0', { 
    exclude module: 'stax' 
    exclude module: 'stax-api' 
    exclude module: 'xpp3' 
}) 

    Retrofit retrofit = new Retrofit.Builder() 
      .baseUrl(HOST) 
      .client(client) 
      .addConverterFactory(SimpleXmlConverterFactory.create()) 
      .build(); 
    service = retrofit.create(Service.class); 
+0

ありがとうございました! '構成{ compile.excludeグループ: 'STAX' compile.exclude基: 'xpp3' }私のGradleファイルに 'LIBS'、含まれる:[ '*の.jar'] – ku4irka

+0

依存関係{ fileTree(DIRはコンパイル) testCompile 'JUnitの:JUnitの:4.12' コンパイル 'com.android.support:appcompat-v7:24.1.1' コンパイル 'com.android.support:design:24.1.1' コンパイル「com.android。サポート:recyclerview-v7:24.1.1 ' コンパイル' com.squareup.retrofit2:retrofit:2.1.0 ' コンパイル' com.squareup.retrofit2:converter-simplexml:2.1.0 ' コンパイル' com.squareup。ピカソ:ピカソ:2.5.2 ' コンパイル' com.squareup .okhttp3:okhttp:3.3.1 ' をコンパイル' org.simpleframework:simple-xml:2.7.1 ' } – ku4irka

関連する問題