我正在尝试使用 Set。但是我在第一次出现 add() 函数时出错.. -innerSetException(futurTask.java:273) -setException(FutureTask.java:124)。所以我真的不明白......我真的希望你能帮助我!这是我的代码:
public class RetrieveArticleTask extends AsyncTask<Void, Void, Set<Article>> {
private List<Article> articles;
private List<Article> products ;
private Set<Article> productsUpdates;
private LoginTaskListener callbackArticlesReceived;
public RetrieveArticleTask(AutoCompletionActivity callback) {
this.articles = new ArrayList<Article>(200);
this.products = new ArrayList<Article>(200);
this.productsUpdates = new TreeSet<Article>();
this.callbackArticlesReceived = callback;
}
@Override
protected Set<Article> doInBackground(Void... aVoid) {
try {
List<ArticleResult> articleResults = RetailReloadWebServicesArticle.getListArticlesAll();
for(ArticleResult articleResult : articleResults ){
articles.add(new Article(articleResult));
System.out.println(productsUpdates.size());
productsUpdates.add(new Article(articleResult));
}
System.out.println("article size : " + articles.size());
} catch (ITException e) {
e.printStackTrace();
System.out.println("ERROR :::" +e);
}
try {
products = RetailReloadApplication.getSqliteOpenHelper().getArticleDao().getAllObjects();
} catch (ITException e) {
e.printStackTrace();
}
System.out.println(products.size());
for(Article product : products ){
productsUpdates.add(product);
}
try {
if(productsUpdates != null){
for(Article productUpdate : productsUpdates ){
RetailReloadApplication.getSqliteOpenHelper().getArticleDao().addOrUpdateObject(productUpdate);
}
}
} catch (ITException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return productsUpdates;
}
@Override
protected void onPostExecute(Set<Article> articles) {
System.out.println(articles.size());
if (null != callbackArticlesReceived)
callbackArticlesReceived.onLoginTaskFinished(articles);
}
}
这里是完整的堆栈跟踪:所以这里是堆栈跟踪:
07-04 08:13:17.322: E/AndroidRuntime(652): java.lang.RuntimeException: An error occured while executing doInBackground()
07-04 08:13:17.322: E/AndroidRuntime(652): at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-04 08:13:17.322: E/AndroidRuntime(652): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.lang.Thread.run(Thread.java:856)
07-04 08:13:17.322: E/AndroidRuntime(652): Caused by: java.lang.ClassCastException: com.retailreload.service.model.result.article.ArticleResult is not Comparable
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.TreeMap.find(TreeMap.java:254)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.TreeMap.putInternal(TreeMap.java:240)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.TreeMap.put(TreeMap.java:186)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.TreeSet.add(TreeSet.java:113)
07-04 08:13:17.322: E/AndroidRuntime(652): at com.retailreload.task.RetrieveArticleTask.doInBackground(RetrieveArticleTask.java:48)
07-04 08:13:17.322: E/AndroidRuntime(652): at com.retailreload.task.RetrieveArticleTask.doInBackground(RetrieveArticleTask.java:1)
07-04 08:13:17.322: E/AndroidRuntime(652): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-04 08:13:17.322: E/AndroidRuntime(652): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-04 08:13:17.322: E/AndroidRuntime(652): ... 5 more