2014-10-31 39 views
1

我在使用robospice中的spring android。我需要放置获取请求标题,所以我使用了exchange()方法。该代码有没有错误,但没有任何获取Robospice loadDataFromNetwork()不工作

public MList loadDataFromNetwork() throws Exception { 
     HttpHeaders headers = new HttpHeaders(); 
     headers.add(key,keyValue); 
     HttpEntity entity = new HttpEntity(headers); 
     ResponseEntity<MList> response=getRestTemplate().exchange(url,HttpMethod.GET,entity,MList.class); 
     return getRestTemplate().exchange(url, HttpMethod.GET,new HttpEntity<Object> (headers),MList.class).getBody(); 
    } 
+0

那你尝试调试时?该方法甚至被称为? – Snicolas 2014-11-01 12:17:09

回答

1
RestTemplate restTemplate=new RestTemplate(); 
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); 
    HttpHeaders headers = new HttpHeaders(); 
    headers.add(key,keyValue); 
    HttpEntity entity = new HttpEntity(headers); 
    ResponseEntity<Pojo> response=restTemplate.exchange(url,HttpMethod.GET,entity,Pojo.class); 
    return response.getBody(); 

它工作时,我编辑这样的代码。

但我得到一个空指针异常使用

RestTemplate restTemplate=getRestTemplate(); 
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter())