当我尝试使用Spring for Android进行网络交换时,我有一个空指针
堆栈追踪:
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): 21:25:54.169 pool-2-thread-1 An exception occured during request network execution :null
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): java.lang.NullPointerException
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(SimpleClientHttpResponse.java:62)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:476)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:438)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:414)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at com.xxx.xxx.rest.SongPostRequest.loadDataFromNetwork(SongPostRequest.java:43)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at com.xxx.xxx.rest.SongPostRequest.loadDataFromNetwork(SongPostRequest.java:1)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at com.octo.android.robospice.request.CachedSpiceRequest.loadDataFromNetwork(CachedSpiceRequest.java:26)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at com.octo.android.robospice.request.RequestProcessor.processRequest(RequestProcessor.java:214)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at com.octo.android.robospice.request.RequestProcessor$1.run(RequestProcessor.java:146)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
11-28 21:25:54.164: E//RequestProcessor.java:226(5225): at java.lang.Thread.run(Thread.java:856)
堆栈跟踪所在的SongPostRequest
:
@Override
public Response loadDataFromNetwork() throws Exception {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(new MediaType("application", "json"));
requestHeaders.set("Userid", String.valueOf(user.getId()));
HttpEntity<ListenedSong> requestEntity = new HttpEntity<ListenedSong>(
requestHeaders);
RestTemplate restTemplate = getRestTemplate();
try {
ResponseEntity<Response> response = restTemplate.exchange("http://192.168.1.117/Project56/web/app_dev.php/mobile/music_new", HttpMethod.POST, requestEntity, Response.class);
return response.getBody();
} catch (HttpClientErrorException e) {
Log.e(LOGTAG, e.toString());
}
return null;
}
来自服务器的响应获取状态代码(200),所以我不明白为什么它在那里为空?
看起来我使用的库中的SimpleClientHttpResponse
有一个bug。谁知道更多关于这个?