gpt4 book ai didi

java - 找不到类 'org.codehaus.jackson.io.SegmentedStringWriter' ,从方法 org.codehaus.jackson.map.ObjectMapper.writeValueAsString 引用

转载 作者:太空宇宙 更新时间:2023-11-04 14:44:30 38 4
gpt4 key购买 nike

我创建了一个服务

公共(public)类 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;

}

}

然后我创建了一个这样的请求

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



}

我在 Activity 中调用那个

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());

}

}

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

最佳答案

这些类位于不同的 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>

如果没有,您可以在这里获取 jar :

http://wiki.fasterxml.com/JacksonDownload

关于java - 找不到类 'org.codehaus.jackson.io.SegmentedStringWriter' ,从方法 org.codehaus.jackson.map.ObjectMapper.writeValueAsString 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24585151/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com