我创建了一项服务
公共类JsonSpiceService扩展了SpringAndroidSpiceService {
@Override
public RestTemplate createRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
// find more complete examples in RoboSpice Motivation app
// to enable Gzip compression and setting request timeouts.
// web services support json responses
MappingJacksonHttpMessageConverter jsonConverter =
new MappingJacksonHttpMessageConverter();
FormHttpMessageConverter formHttpMessageConverter =
new FormHttpMessageConverter();
StringHttpMessageConverter stringHttpMessageConverter =
new StringHttpMessageConverter();
final List<HttpMessageConverter<?>> listHttpMessageConverters =
restTemplate.getMessageConverters();
listHttpMessageConverters.add(jsonConverter);
listHttpMessageConverters.add(formHttpMessageConverter);
listHttpMessageConverters.add(stringHttpMessageConverter);
restTemplate.setMessageConverters(listHttpMessageConverters);
// @see http://sapandiwakar.in/eofexception-with-spring-rest-template-android/
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
return restTemplate;
}
@Override
public CacheManager createCacheManager(Application application)
throws CacheCreationException {
CacheManager cacheManager = new CacheManager();
JacksonObjectPersisterFactory jacksonObjectPersisterFactory =
new JacksonObjectPersisterFactory(application);
cacheManager.addPersister(jacksonObjectPersisterFactory);
return cacheManager;
}
}
然后我创建了一个类似的请求
公共类PractitionerRequest扩展了SpringAndroidSpiceRequest {
final String TAG="ROBOSPICE";
public PractitionerRequest() {
super(PractList.class);
// TODO Auto-generated constructor stub
}
@Override
public PractList loadDataFromNetwork() throws Exception{
URL url = new URL("http://svv.in.net/service/test.php");
Log.d(TAG, ""+url);
return getRestTemplate().getForObject(url.toURI(), PractList.class);
//return getRestTemplate().getForObject(url, PractList.class);
}
}
这是我的POJO课程
public class PractList {
String name;
String hobbies;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHobbies() {
return hobbies;
}
public void setHobbies(String hobbies) {
this.hobbies = hobbies;
}
}
我正在调用Acitivity中的那个
SpiceManager spiceManager = new SpiceManager(JsonSpiceService.class);
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "starting service");
spiceManager.start(this);
}
@Override
protected void onStop() {
if( spiceManager.isStarted() ) {
spiceManager.shouldStop();
Log.d(TAG, "stopping service");
}
super.onStop();
}
private void performRequest() {
AdminActivity.this.setProgressBarIndeterminateVisibility(true);
PractitionerRequest request = new PractitionerRequest();
spiceManager.execute(request, "sss", DurationInMillis.ONE_MINUTE, new PractRequestListerner());
}
private void roboSpice() {
performRequest();
Log.d(TAG, "started");
/*Log.d(TAG, "started");
PractitionerRequest request=new PractitionerRequest();
spiceManager.execute(request,"Json",DurationInMillis.ONE_MINUTE, new PractitionerRequestListener());
Log.d(TAG, "started:"+request.toString());
Log.d(TAG, "end");*/
/*new PractRequestListerner();
if (isPageInCache()) {
showMsg("The page is already cached.");
Log.d(TAG, "The page is already cached");
}
*/
}
private boolean isPageInCache() {
String pageName="yes";
try {
PractitionerRequest request=new PractitionerRequest();
spiceManager.execute(request,"Json",DurationInMillis.ONE_MINUTE, new PractitionerRequestListener());
} catch (Exception e) {
return false;
}
return true;
}
public void onRequestSuccess(PractList practList) {
// setProgressBarIndeterminateVisibility(false);
Log.d(TAG, "*******************");
Log.e("TEST",practList.getName());
Log.e("TEST",practList.getHobbies());
}
public void onRequestFailure(SpiceException spiceException) {
setProgressBarIndeterminateVisibility(false);
final String msg = spiceException.getCause().getMessage();
showMsg("Error: " + msg);
}
private void showMsg(String msg) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
class PractRequestListerner implements RequestListener<PractList>{
@Override
public void onRequestFailure(SpiceException e) {
Log.e("TEST","fail");
Log.e("TEST","fail"+e.getMessage());
}
@Override
public void onRequestSuccess(PractList list) {
Log.e("TEST","succes");
Log.e("TEST","fail"+list.getName());
}
}
但是我收到这些错误没有得到确切的错误
答案 0 :(得分:0)
这些课程在不同的广告系列中 - 如果您的jackson-databind.jar
没有jackson-core.jar
,则会收到此错误。
如果您正在使用maven,请将其添加到您的pom:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.1.1</version>
</dependency>
如果没有,你可以在这里拿到罐子: