我已经使用infinteScrollAdapter和json中的connectionRequest来填充组件,但有时它会产生以下错误,而它通常运行良好。这可能是什么问题?如果我再次运行它工作正常但它有时会挂起很长时间然后显示此错误
int sizethumb = 0;
int sizethumb1 = 0;
if (responsesImg.size() > 0) {
sizethumb = largePlaceholder.getWidth();
sizethumb1 = largePlaceholder.getHeight();
findMainImg(f).setPreferredSize(new Dimension(sizethumb, sizethumb1));
findMainImg(f).getAllStyles().setBgImage(URLImage.createToStorage(largePlaceholder, newsImgFilename + "_0_ y", responsesImg.get(0).get("image_url"), URLImage.RESIZE_SCALE_TO_FILL));
mainImageImgViewer = null;
mainImageImgViewer = findMainImg(f).getUnselectedStyle().getBgImage();
}
if (responsesImg != null) {
if (responsesImg.size() > 1) {
sizethumb = thumbnail.getWidth();
sizethumb1 = thumbnail.getHeight();
findNewsThumbnail1(f).getAllStyles().setBgImage(URLImage.createToStorage(largePlaceholder, newsImgFilename + "_0_ x", responsesImg.get(1).get("image_url"), URLImage.RESIZE_SCALE_TO_FILL));
findNewsThumbnail1().setPreferredSize(new Dimension(sizethumb, sizethumb1));
thumbnail1 = null;
thumbnail1 = findNewsThumbnail1(f).getUnselectedStyle().getBgImage();
}
if (responsesImg.size() > 2) {
findNewsThumbnail2().setPreferredSize(new Dimension(sizethumb, sizethumb1));
System.out.println("thumbnail img " + responsesImg.get(2).get("image_url"));
findNewsThumbnail2(f).getAllStyles().setBgImage(URLImage.createToStorage(largePlaceholder, newsImgFilename + "_0_ w", responsesImg.get(2).get("image_url"), URLImage.RESIZE_SCALE_TO_FILL));
thumbnail2 = null;
thumbnail2 = findNewsThumbnail2(f).getUnselectedStyle().getBgImage();
} else if (responsesImg.size() == 0) {
System.out.println("null images");
}
}
我的代码:
class MR extends ConnectionRequest {
private Map<String, Object> resultsdata;
private Vector<Map<String, Object>> responses;
@Override
protected void readResponse(InputStream input) throws IOException {
JSONParser p = new JSONParser();
resultsdata = p.parse(new InputStreamReader(input));
responses = (Vector<Map<String, Object>>) resultsdata.get("root");
newsImageArray = new ArrayList();
for (int i = 0; i < responses.size(); i++) {
Hashtable hm = (Hashtable) responses.get(i);
newsDetailHome = (String) hm.get("details");
newsDateHome = (String) hm.get("date");
newsTimeHome = (String) hm.get("time");
newsTitleHome = (String) hm.get("title");
responsesImg = new Vector<>();
if (hm.get("photo").toString() != "[]") {
responsesImg = (Vector) hm.get("photo");
} else {
}
}
}
@Override
protected void handleErrorResponseCode(int code, String message) {
Dialog.show("Error msg", "The server returned the error code: " + code, "ok", null);
}
@Override
protected void handleException(Exception err) {
Dialog.show("Connection msg", "There was a connection error: " + err, "ok", null);
}
};
MR r = new MR();
r.setPost(false);
if (newsIdValueFromHome == null) {
r.setUrl("http://capitaleyedevelopment.com/~admin/traffic/api/news/getNewsDetails?news_id=" + newsIdValue);
} else {
r.setUrl("http://capitaleyedevelopment.com/~admin/traffic/api/news/getNewsDetails?news_id=" + newsIdValueFromHome);
}
r.setDuplicateSupported(true);
NetworkManager.getInstance().shutdownSync();
NetworkManager.getInstance().addToQueueAndWait(r);
我的联系:
com.codename1.impl.javase.JavaSEPort$EDTViolation: EDT Violation Stack!
EDT violation detected!
Rendering frame took too long 344 milliseconds
Rendering frame took too long 156 milliseconds
at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:404)
at com.codename1.impl.javase.JavaSEPort.getImageWidth(JavaSEPort.java:3449)
at com.codename1.ui.Image.getWidth(Image.java:667)
at com.codename1.ui.EncodedImage.getWidth(EncodedImage.java:471)
at com.codename1.ui.URLImage$ScaleToFill.adaptImage(URLImage.java:81)
at com.codename1.ui.URLImage$DownloadCompleted.run(URLImage.java:159)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:103)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:140)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
com.codename1.impl.javase.JavaSEPort$EDTViolation: EDT Violation Stack!
at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:404)
at com.codename1.impl.javase.JavaSEPort.getImageHeight(JavaSEPort.java:3460)
at com.codename1.ui.Image.getHeight(Image.java:681)
at com.codename1.ui.Image.scaledLargerRatio(Image.java:877)
EDT violation detected!
at com.codename1.ui.URLImage$ScaleToFill.adaptImage(URLImage.java:82)
at com.codename1.ui.URLImage$DownloadCompleted.run(URLImage.java:159)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:103)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:140)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
com.codename1.impl.javase.JavaSEPort$EDTViolation: EDT Violation Stack!
at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:404)
at com.codename1.impl.javase.JavaSEPort.getImageWidth(JavaSEPort.java:3449)
at com.codename1.ui.Image.getWidth(Image.java:667)
at com.codename1.ui.Image.scaledLargerRatio(Image.java:878)
at com.codename1.ui.URLImage$ScaleToFill.adaptImage(URLImage.java:82)
at com.codename1.ui.URLImage$DownloadCompleted.run(URLImage.java:159)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:103)
EDT violation detected!
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:140)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
com.codename1.impl.javase.JavaSEPort$EDTViolation: EDT Violation Stack!
at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:404)
at com.codename1.impl.javase.JavaSEPort.getImageWidth(JavaSEPort.java:3449)
at com.codename1.ui.Image.getWidth(Image.java:667)
at com.codename1.ui.Image.scaledLargerRatio(Image.java:882)
at com.codename1.ui.URLImage$ScaleToFill.adaptImage(URLImage.java:82)
at com.codename1.ui.URLImage$DownloadCompleted.run(URLImage.java:159)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:103)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:140)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
com.codename1.impl.javase.JavaSEPort$EDTViolation: EDT Violation Stack!
at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:404)
EDT violation detected!
at com.codename1.impl.javase.JavaSEPort.getImageHeight(JavaSEPort.java:3460)
at com.codename1.ui.Image.getHeight(Image.java:681)
at com.codename1.ui.Image.scaledLargerRatio(Image.java:882)
at com.codename1.ui.URLImage$ScaleToFill.adaptImage(URLImage.java:82)
at com.codename1.ui.URLImage$DownloadCompleted.run(URLImage.java:159)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:103)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:140)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
com.codename1.impl.javase.JavaSEPort$EDTViolation: EDT Violation Stack!
at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:404)
at com.codename1.impl.javase.JavaSEPort.scale(JavaSEPort.java:3479)
at com.codename1.ui.Image.scale(Image.java:961)
at com.codename1.ui.Image.scaledImpl(Image.java:931)
at com.codename1.ui.Image.scaled(Image.java:896)
EDT检测
import nltk
import random
from nltk.corpus import movie_reviews
documents = [(list(movie_reviews.words(fileid)), category)
for category in movie_reviews.categories()
for fileid in movie_reviews.fileids(category)]
random.shuffle(documents)
all_words = []
for w in movie_reviews.words():
all_words.append(w.lower())
all_words = nltk.FreqDist(all_words)
word_features = list(all_words.keys())[:3000]
def find_features(document):
words = set(document)
features = {}
for w in word_features:
features[w] = (w in words)
return features
featuresets = [(find_features(rev), category) for (rev, category) in documents]
training_set = featuresets[:1900]
testing_set = featuresets[1900:]
classifier = nltk.NaiveBayesClassifier.train(training_set)
print("Classifier accuracy percent:",(nltk.classify.accuracy(classifier, testing_set))*100)
答案 0 :(得分:0)
那里有很多代码,但不是全部,所以我无法对此发表评论。我确实注意到每次出错都会关闭网络。你应该只在非常极端的情况下调用shutdown。
此异常报告我们的事件队列已完全填满。这是一个疯狂的情况,只有当本地代码在EDT保持到位时继续发送事件时才能达到这种情况。在模拟器中打开EDT违规检测工具,它可能会指向实际的违规行为。
要了解有关EDT的更多信息,请查看developer guide。