- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下代码...
public interface GithubService {
@GET("/repos/{owner}/{repo}/contributors")
public List<Contributor> contributors(@Path("owner") String owner, @Path("repo") String repo);
}
RepositoresBusinessController.class
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("https://api.github.com").build();
GithubService service = restAdapter.create(GithubService.class);
listContributors = service.contributors(username, "retrofit");
Log.d("List Contributors", listContributors+" ");
贡献者类
public class Contributor {
String login;
int contributions;
}
并且不要在 Log 中打印并且应用程序会退出......有一部分异常
725-725/com.example.githubapiexample E/AndroidRuntime﹕ FATAL EXCEPTION: main
code here`retrofit.RetrofitError
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
有人知道为什么吗?谢谢
最佳答案
Retrofit 具有异步回调机制,无需使用 AsyncTask
或服务。更改您的界面以使用回调而不是返回类型——
public interface GithubService {
@GET("/repos/{owner}/{repo}/contributors")
public void contributors(@Path("owner") String owner, @Path("repo") String repo,
Callback<List<Contributor>> contributors);
}
你可以这样调用它——
service.contributors(username, project, new Callback<List<Contributor>>() {
@Override
public void success(List<Contributor> contributors, Response response) {
// got the list of contributors
}
@Override
public void failure(RetrofitError error) {
// Code for when something went wrong
}
});
关于android - RetrofitError 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27141610/
我有以下代码... public interface GithubService { @GET("/repos/{owner}/{repo}/contributors") public
当我尝试运行下面给出的 RoboSpice-Retrofit 示例时 https://github.com/octo-online/RoboSpice-samples/tree/release/rob
我正在开发一个利用 Retrofit 进行 api 调用的 android 应用程序。当我调用以下代码时: String searchText = query; RestAdapter restAda
我正在使用改造来进行 post api 调用,在尝试到达端点时出现以下错误。 Caused by: rx.exceptions.OnErrorNotImplementedException:
我正在使用 Robospice 提供的 Retrofit 模块。我正在进行异步改造调用。问题是,如果我的调用不成功,我会收到 Retrofit Error,但在 robospice 中,我会在 onS
使用 Retrofit 1.6.0、OkHTTP 2.0.0 和 OkHTTP-UrlConnection 2.0.0。 我正在对一个不存在的 URL 使用 Retrofit 对服务进行 POST。正
我正在使用 Retrofit 库对我正在使用的服务进行 REST 调用。 如果我对我的服务进行 API 调用并出现故障,该服务会返回一些 JSON 以及标准 HTTP 错误内容。使用失败回调中包含的
我想使用 Retorfit 2 实现错误处理机制。 可用的解决方案是使用我在当前存储库中找不到的 RetrofitError 类。 最佳答案 如果你是同步请求,你在接口(interface)中定义你的
我正在使用库 com.squareup.retrofit:retrofit:1.9.0,以便从我的 android 应用程序向我的服务器发送数据。 其实,当我想向服务器发送请求时,我发现了这个错误:
我搜索了很多,我找到了一些这样的解决方案: System.setProperty("http.keepAlive", "false"); arg0.addHeader("Connection", "c
在 Retrofit 1.9.x 中有一个 RetrofitError.Kind.NETWORK这让您可以轻松确定故障是否由网络错误引起。在新的 2.0 API 中,我们不再有 RetrofitErr
我在一个大项目中使用 Retrofit 1.9,即使调用失败也必须检查响应 header 中的一些数据 - 例如分析请求代码。我们已经知道异步调用的结构: RestClient.get().a
我正在使用 RetroFit 版本 1.9.0 发出 PUT 请求以将图像添加到某个位置,同时还使用访问 cookie,但在图像传输正确开始之前,我收到错误: 09-14 13:35:12.718
我是一名优秀的程序员,十分优秀!