因此,我正在使用具有名为"public"的变量的API进行改造.我将如何让它像所有其他变量一样自动映射.
例:
@GET("/?filter=my_images")
void getMyImages(
@Query("client_id") String id,
@Query("api_key") String key,
Callback<ImageList> callback
);
public static class Image{
int id;
String name;
String distribution;
String slug;
// Can't do this:
boolean public;
}
public static class ImageList{
String status;
List<Image> images;
}
Run Code Online (Sandbox Code Playgroud)
示例API结果(json):
{
"status": "OK",
"images": [
{
"id": 1,
"name": "My first snapshot",
"distribution": "Ubuntu",
"slug": "ubuntu-12.10-x32",
"public": true
},
{
"id": 2,
"name": "Automated Backup",
"distribution": "Ubuntu"
}
]
}
Run Code Online (Sandbox Code Playgroud) 所以当我说我在尝试运行时在这两个错误之间来回反复HttpClient.execute(HttpPost).入门IllegalStateException
public class NetMethods {
private static HttpClient client = new DefaultHttpClient();
public static void getStuff() {
ArrayList<Alarm> alarms = new ArrayList<Alarm>();
HttpPost post = HttpPostFactory.getHttpPost("GetStuff");
StringBuilder builder = new StringBuilder();
HttpResponse response = client.execute(post); // Exception thrown here
...
Run Code Online (Sandbox Code Playgroud)
另外,我的MttpPostFactory就是这个
import org.apache.http.client.methods.HttpPost;
public class HttpPostFactory {
private static final String url = "http://example.com/ExampleFolder/";
public static HttpPost getHttpPost(String s) {
return new HttpPost(url + s);
}
}
Run Code Online (Sandbox Code Playgroud) 说我有这样一个类:
public class FileMethods {
private static final Document doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
public static void doSomething(){
}
}
Run Code Online (Sandbox Code Playgroud)
我如何正确初始化文档?这当前抛出了编译错误(未捕获的异常),因此可以在没有显式方法调用的情况下初始化doc吗?