我创建了一个服务

公共类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;
        }



}


我称它为主动性

SpiceManager spiceManager =新的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());

    }

}


但我得到这些错误没有得到确切的错误

最佳答案

这些类位于不同的jar中-如果您的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>


如果没有,您可以在这里获得罐子:

http://wiki.fasterxml.com/JacksonDownload

07-28 06:31