0

使用此代码:

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!
...

我错过了什么!!?

4

1 回答 1

1

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

似乎您正在setText其他地方调用 EDT,但您切断了指向该位置的堆栈跟踪。

编辑:

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

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

于 2014-03-10T05:03:42.613 回答