Java 2基本获取示例代码
我是Android新手,正在尝试在github上使用带有基本SimpleService.java的改型2。这个示例运行得很好,但是当使用myURL时,我得到了一个Java 2基本获取示例代码,java,android,retrofit2,Java,Android,Retrofit2,我是Android新手,正在尝试在github上使用带有基本SimpleService.java的改型2。这个示例运行得很好,但是当使用myURL时,我得到了一个NullPointerException: Thread thread = new Thread(new Runnable(){ @Override public void run(){ Retrofit retrofit = new Retrofit.Builde
NullPointerException
:
Thread thread = new Thread(new Runnable(){
@Override
public void run(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(myURL)
.addConverterFactory(GsonConverterFactory.create())
.build();
// Create an instance of our GitHub API interface.
SimpleService.GitHub github = retrofit.create(SimpleService.GitHub.class);
// Create a call instance for looking up Retrofit contributors.
Call<List<SimpleService.Pending>> call2 = github.getPendings();
List<SimpleService.Pending> pendings = null;
try {
pendings = call2.execute().body();
} catch (IOException e) {
e.printStackTrace();
}
for (SimpleService.Pending pending : pendings) {
System.out.println(pending.idpr + " ;;; " + pending.lastlat + " ;;; " + pending.lastlng);
}
}
});
thread.start();
下面是我收到的典型json:
[
{"idpr":1,"lastlat":48.788986,"lastlng":7.24545,"idu":{"username":"foulekparo"}},
{"idpr":2,"lastlat":48.803717,"lastlng":6.47526,"idu":{"username":"flouka"}}
]
我不知道我做错了什么。你的myURL的值是多少?这是myURL:你的myURL的值是多少?这是myURL:
[
{"idpr":1,"lastlat":48.788986,"lastlng":7.24545,"idu":{"username":"foulekparo"}},
{"idpr":2,"lastlat":48.803717,"lastlng":6.47526,"idu":{"username":"flouka"}}
]