背景Robospice存儲對象,通過Ormlite擴展數據庫中的ArrayList
我一直在試圖修改Robospice Ormlite example code,我已經成功運行。我所做的唯一更改是我有一個包含對象數組的JSON響應。
我創建2類:
public class Foos extends ArrayList<Foo>
public class Foo
我有最初的問題,因爲我的JSON響應是一個純粹的陣列沒有外容器。我通過google羣體閱讀,解決這個問題的方法是創建一個擴展ArrayList的「假」類(Foos)。這產生了下面的代碼:
public class FooRequest extends SpringAndroidSpiceRequest<Foos> {
private String baseUrl;
public FooRequest() {
super(Foos.class);
this.baseUrl = "http://somewhere.com/jsonurl";
}
@Override
public Foos loadDataFromNetwork() throws RestClientException {
Ln.d("Call web service " + baseUrl);
return getRestTemplate().getForObject(baseUrl, Foos.class);
}
}
然後我創建了以下服務代碼,從這些例子改編而來。
public class MySpiceService extends SpringAndroidSpiceService {
private static final int WEBSERVICES_TIMEOUT = 10000;
@Override
public CacheManager createCacheManager(Application application) {
CacheManager cacheManager = new CacheManager();
List< Class<?>> classCollection = new ArrayList< Class<?>>();
// add persisted classes to class collection
classCollection.add(Foos.class);
// init
RoboSpiceDatabaseHelper databaseHelper = new RoboSpiceDatabaseHelper(application, "sample_database.db", 2);
InDatabaseObjectPersisterFactory inDatabaseObjectPersisterFactory = new InDatabaseObjectPersisterFactory(application, databaseHelper, classCollection);
cacheManager.addPersister(inDatabaseObjectPersisterFactory);
return cacheManager;
}
@Override
public RestTemplate createRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
// set timeout for requests
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
httpRequestFactory.setReadTimeout(WEBSERVICES_TIMEOUT);
httpRequestFactory.setConnectTimeout(WEBSERVICES_TIMEOUT);
restTemplate.setRequestFactory(httpRequestFactory);
// web services support xml 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);
return restTemplate;
}
}
問題
代碼運行但沒有任何力量關閉我從來不打我activity.Neither內RequestListener內部類的成功或失敗消息的方法被解僱,它似乎相當困難調試,所以它感覺像一個「無聲失敗」。
public final class MyRequestListener implements RequestListener<Foos> {
@Override
public void onRequestFailure(SpiceException spiceException) {
Toast.makeText(SampleSpiceActivity.this, "failure", Toast.LENGTH_SHORT).show();
}
@Override
public void onRequestSuccess(final Articles result) {
Toast.makeText(SampleSpiceActivity.this, "success", Toast.LENGTH_SHORT).show();
}
}
我已經試過
我曾嘗試註釋類Foo,與Ormlite註釋,看是否所需的函數庫了援助之手,但仍沒有運氣。如下所示:
@DatabaseTable
public class Foo {
@DatabaseField(generatedId = true)
private int id;
@DatabaseField
private String someText;
}
我不知道這是否是Foos類的結果,當我真的想要一個存儲Foo的數據庫表時。任何建議都會很棒!
RoboSpice附帶調試啓用日誌記錄,是logcat的打印有用的東西? – rciovati 2013-04-04 07:48:27
我一直試着用不同的斷點,但logcat中沒有什麼有趣的東西出現。正如你在代碼中看到的那樣,我也保存了一些調試信息。 – 2013-04-04 08:56:18
在沒有任何回答的情況下在這裏找到同樣的問題https://groups.google.com/forum/?fromgroups=#!searchin/robospice/ormlite/robospice/inqSyQkwGn8/axXhozO7PTIJ – 2013-04-04 15:04:52