(Retrofit) 클래스 충돌 앱에 대한 변환기를 수 없습니다.
따라서 Retrofit 2.0.0이 최근에 사용 방법에 대한 업데이트 된 예제는 없지만 기본 API 호출을 위해 구현됩니다. 나는 점점
java.lang.IllegalArgumentException: Unable to create converter for class`
원인
Caused by: java.lang.IllegalArgumentException: Could not locate converter for class orbyt.app.dataclass. Tried:
* retrofit.OkHttpBodyConverterFactory
API 호출을 시도 할 때.
나는 같은 문제에 직면했다. 다음을 추가하여 수정했습니다.
compile 'com.squareup.retrofit2:converter-gson:<latest-version>'
내 build.gradle에
그런 다음 Retrofit 인스턴스를 만들 때 변환기를 지정합니다.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
Retrofit 2.0에서 변환기는 패키지에 포함되어 있지 않습니다. Retrofit 2.0을 사용하는 경우 새 URL 패턴을 수행합니다.
기본 URL : 항상 /로 끝남
@Url : /로 시작하지
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
2.0에 대한 자세한 내용은이 링크를 클릭하십시오. Retrofit 2.0 : 가장 큰 업데이트
또한 build.gradle을 업데이트하십시오.
그에 따라 개조 버전 변경
나에게 의존 아래 이미 거기에
compile 'com.squareup.retrofit2:retrofit:2.0.2'
gson 2.0.2의 경우 변경
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
그런 다음 추가
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
Retrofit V2의 경우 다음 리포지토리를 추가합니다.
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
이제 아래 코드를 사용하십시오-
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
도움이 되길 바랍니다 :)
최신 Retrofit 2.0에서는 최신 버전을 가져와야합니다.
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
주의해서 호출하십시오 baseUrl()
. v2.0에서는 "/"로 끝나야 메소드에서 "/"로 URL을 시작하지 않습니다.
@POST("classes/info")
Call<ContactBean> insertInfo(@Body ContactBean bean);
그리고 더 많은 정보를 위해 Retrofit 을 볼 수 있습니다 ! 희망 도움!
에서 내 사건 (코 루틴과 코 틀린) 나는 예외를 회의 :
개 조용 변환기를 만들 수 없습니다.
Queries.exportPdf 메소드의 경우.
원인 : java.lang.IllegalArgumentException : retrofit2.Call에 대한 ResponseBody 변환기를 사용할 수 없습니다.
요청에 문제가 있습니다.
@FormUrlEncoded
@Streaming
@POST("export-pdf/")
suspend fun exportPdf(
@Field("token") token: String
): Call<ResponseBody>
suspend
정의에서 제거되는 예외가 제거 되었습니다.
'ProgramingTip' 카테고리의 다른 글
점과 일치하는 정규 배열 (0) | 2020.10.16 |
---|---|
람다 내부에서 지역 변수 수정 (0) | 2020.10.16 |
Android Studio- 프로젝트 평가 리스너 오류를 알리지. (0) | 2020.10.16 |
API <11에 대한 Android invalidateOptionsMenu () (0) | 2020.10.15 |
Spring AOP : JoinPoint와 PointCut의 차이점은 무엇입니까? (0) | 2020.10.15 |