我正在使用 Android Spring Framework 和 Jackson 解析器开发一个 Android 3.1 应用程序。我没有使用 Maven,因为我不知道如何使用它。
我已按以下顺序将以下 jar 添加到我的项目的类路径中:
- 番石榴-11.0.2.jar
- 杰克逊注释-2.0.0.jar
- 杰克逊核心2.0.0.jar
- jackson-databind-2.0.0.jar
- spring-android-core-1.0.0.RC1.jar
- spring-android-rest-template-1.0.0.RC1.jar
发出 REST 请求并进行 JSON 解析的类:
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import com.google.common.collect.Lists;
import es.viacognita.models.Form;
public class FormSpringController
{
public static List<Form> LoadAll()
{
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Collections.singletonList(new MediaType("application","json")));
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
String url = "http://192.168.1.128/RestServiceImpl.svc/forms/";
MappingJacksonHttpMessageConverter messageConverter = new MappingJacksonHttpMessageConverter();
List<HttpMessageConverter<?>> messageConverters = Lists.newArrayList();
messageConverters.add(messageConverter);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setMessageConverters(messageConverters);
ResponseEntity<Form[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Form[].class);
Form[] result= responseEntity.getBody();
return Arrays.asList(result);
}
}
这里:
MappingJacksonHttpMessageConverter messageConverter = new MappingJacksonHttpMessageConverter();
我收到此错误:
java.lang.VerifyError: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
为什么我会收到此错误?
我该如何解决?