2014-10-31 49 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())