相关疑难解决方法(0)

无法在Android Retrofit库中为我的班级创建转换器

我从使用Volley迁移到Retrofit,我已经拥有了我之前使用的gson类,用于将JSONObject响应转换为实现gson注释的对象.当我尝试使用改造来制作http get请求但我的应用程序崩溃时出现此错误:

 Unable to start activity ComponentInfo{com.lightbulb.pawesome/com.example.sample.retrofit.SampleActivity}: java.lang.IllegalArgumentException: Unable to create converter for class com.lightbulb.pawesome.model.Pet
    for method GitHubService.getResponse
Run Code Online (Sandbox Code Playgroud)

我遵循改造网站的指南,我想出了这些实现:

这是我尝试执行复古http请求的活动:

public class SampleActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sample);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("**sample base url here**")
                .build();

        GitHubService service = retrofit.create(GitHubService.class);
        Call<Pet> callPet = service.getResponse("41", "40");
        callPet.enqueue(new Callback<Pet>() {
            @Override
            public void onResponse(Response<Pet> response) {
                Log.i("Response", response.toString());
            }

            @Override
            public void onFailure(Throwable t) {
                Log.i("Failure", t.toString());
            }
        });
        try{
            callPet.execute();
        } …
Run Code Online (Sandbox Code Playgroud)

android gson retrofit

118
推荐指数
7
解决办法
7万
查看次数

标签 统计

android ×1

gson ×1

retrofit ×1