Codename One上的EDT违规

时间:2014-03-10 00:33:46

标签: codenameone network-connection

使用此代码:

protected void second_ButtonAction(Component c, ActionEvent event) {
  ConnectionRequest cn = new ConnectionRequest(); 

  cn.setUrl(theURLaddress);
  cn.setPost(false);  
  cn.addArgument("name", "this");

  NetworkManager.getInstance().addToQueueAndWait(cn);
  cn.getResponseData();
}

我不断收到以下信息:

EDT violation detected!
com.codename1.impl.javase.JavaSEPort$EDTViolation: EDT Violation Stack!
at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:344)
EDT violation detected!
EDT violation detected!
EDT violation detected!
at com.codename1.impl.javase.JavaSEPort.isNativeInputSupported(JavaSEPort.java:2459)
at com.codename1.ui.Display.isNativeInputSupported(Display.java:2306)
at com.codename1.ui.TextArea.setText(TextArea.java:406)
at com.codename1.ui.TextArea.<init>(TextArea.java:328)
at com.codename1.ui.TextArea.<init>(TextArea.java:257)
at com.codename1.ui.Dialog.show(Dialog.java:771)
at com.codename1.ui.Dialog.show(Dialog.java:727)
at com.codename1.ui.Dialog.show(Dialog.java:692)
at com.codename1.ui.Dialog.show(Dialog.java:536)
at com.codename1.ui.Dialog.show(Dialog.java:788)
at com.codename1.io.ConnectionRequest.handleErrorResponseCode(ConnectionRequest.java:680)
at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:379)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:261)
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:344)
at com.codename1.impl.javase.JavaSEPort.getImageWidth(JavaSEPort.java:3087)
at com.codename1.ui.Image.getWidth(Image.java:667)
at com.codename1.ui.EncodedImage.getWidth(EncodedImage.java:413)
at com.codename1.ui.plaf.Border.getMinimumWidth(Border.java:200)
at com.codename1.ui.Container.calcPreferredSize(Container.java:1431)
at com.codename1.ui.Component.calcScrollSize(Component.java:579)
at com.codename1.ui.Component.getScrollDimension(Component.java:566)
at com.codename1.ui.Container.isScrollableY(Container.java:1495)
at com.codename1.ui.Component.isScrollable(Component.java:1413)
at com.codename1.ui.Container.setLayout(Container.java:246)
at com.codename1.ui.Dialog.<init>(Dialog.java:205)
at com.codename1.ui.Dialog.<init>(Dialog.java:189)
at com.codename1.ui.Dialog.<init>(Dialog.java:180)
at com.codename1.ui.Dialog.show(Dialog.java:952)
EDT violation detected!
...

我错过了什么!!?

1 个答案:

答案 0 :(得分:1)

除了缺乏进度指示外,上面的代码看起来还不错。

你似乎在其他地方从EDT调用setText,但是你切断了指向它的堆栈跟踪。

<强>编辑:

从修改后的堆栈跟踪看来,这一行很重要: 在com.codename1.io.ConnectionRequest.handleErrorResponseCode(ConnectionRequest.java:680)

您正在调用handleErrorResponseCode,这意味着该URL返回了错误代码。所以我们向您展示一个错误对话框。是的,它确实违反了EDT(这些例外是在模拟器中警告潜在的错误)。您需要决定如何处理错误响应代码并通过派生连接请求并覆盖此方法或通过将错误处理程序绑定到网络管理器或通过在连接请求上调用setFailSilently(true)来适当地处理它们。