我是安卓应用程序开发的新手,.I研究了一些在线教程和wiki,并开始开发将调用API托管在Apache服务器(PHP+SLIM+MySQL)..I上的应用程序,已经创建了一些API,并在RESTClient for Chrome上成功地测试了它们。
对于安卓系统,经过一些研究后,我决定使用Square的改进库,它看起来非常高效(比在android上实现的Apache.http协议快5-6倍,比Volley和Robospice快2-3倍)和非常轻的内存占用。
我创建了一个示例Android项目(使用AndroidStudio0.8beta),并通过遵循他们的文档实现了Rertofit。但是,当我编译了我的项目并将我的apk烧到我的phone...it时,java.lang.IllegalStateException无法执行,.following是我实现的细节。
我不知道如何纠正这个错误,...am,我在声明文件中遗漏了什么,或者没有实现我应该实现的任何方法。
库(包括所有gradle依赖项)--我正在包括
结构
public class MyStructures {
public static class Contributor {
public String login;
public int contributions;
}
}接口
public interface MyInterface {
@GET("/repos/{owner}/{repo}/contributors")
List<Contributor> contributors(
@Path("owner") String owner,
@Path("repo") String repo
);
}创建适配器,调用REST方法,结果获取
private static final String API_URL = "https://api.github.com";
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(API_URL)
.build();
// Create an instance of our GitHub API interface.
MyInterface myInterface = restAdapter.create(MyInterface.class);
// Fetch and print a list of the contributors to this library.
List<Contributor> contributors = myInterface.contributors("square", "retrofit");
for (Contributor contributor : contributors) {
System.out.println(contributor.login + " (" + contributor.contributions + ")");
}报表文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication" >
<!-- added this two permission by looking in to some answer on stackoverflow
which i geuss not required for newer android version since googles has given n/w permission by default-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>发布于 2015-01-05 07:29:33
我第一次遇到这个问题是通过在清单中添加以下权限来解决的
<uses-permission android:name="android.permission.INTERNET" /> https://stackoverflow.com/questions/25740236
复制相似问题