Swing,远程桌面异常

时间:2013-10-14 13:31:22

标签: java windows swing remote-desktop indexoutofboundsexception

当我使用Windows远程桌面连接到运行我的应用程序的PC时,我的Swing应用程序似乎抛出ArrayIndexOutOfBounds例外。知道可能导致这种情况的原因吗?

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3
    at sun.awt.Win32GraphicsEnvironment.getDefaultScreenDevice(Win32GraphicsEnvironment.java:96)
    at sun.awt.windows.WWindowPeer.updateGC(WWindowPeer.java:470)
    at sun.awt.windows.WWindowPeer.displayChanged(WWindowPeer.java:508)
    at sun.awt.windows.WWindowPeer$1.run(WWindowPeer.java:448)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:708)
    at java.awt.EventQueue$4.run(EventQueue.java:706)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

我在远程登录PC时已经看过两次,但在其他情况下我从未见过它。因为它全部都在 Java 7u25 Sun JDK 内部(请看下面的堆栈跟踪),我甚至不确定如何调试它。想法?


其他信息:本机有两块显卡,每块显卡有两个显示器端口,Windows配置为打开所有四个显示器。但是,当我远程进入机器时,显然只有一台显示器。具有开始菜单的监视器(以及包含该应用程序的监视器)被Windows识别为监视器#4。

System.getProperties().list(System.out);

-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=D:\Program Files\Java\jdk1.7.0_25\jre...
java.vm.version=23.25-b01
java.vm.vendor=Oracle Corporation
java.vendor.url=http://java.oracle.com/
path.separator=;
java.vm.name=Java HotSpot(TM) 64-Bit Server VM
file.encoding.pkg=sun.io
user.script=
user.country=US
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=Service Pack 1
java.vm.specification.name=Java Virtual Machine Specification
user.dir=C:\Code\workspace\client
java.runtime.version=1.7.0_25-b16
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=D:\Program Files\Java\jdk1.7.0_25\jre...
os.arch=amd64
java.io.tmpdir=XXXXXXXXXXXXXXXXXXXXXXXXXXXX
line.separator=

java.vm.specification.vendor=Oracle Corporation
user.variant=
os.name=Windows 7
sun.jnu.encoding=Cp1252
java.library.path=D:\Program Files\Java\jdk1.7.0_25\bin...
java.specification.name=Java Platform API Specification
java.class.version=51.0
sun.management.compiler=HotSpot 64-Bit Tiered Compilers
os.version=6.1
user.home=XXXXXXXXXXXXXXXXXXXXXXXXX
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.7
user.name=XXXXXXXXXXXXXXXXXXXXXXXXX
java.class.path=C:\Code\workspace\client\target\class...
java.vm.specification.version=1.7
sun.arch.data.model=64
java.home=D:\Program Files\Java\jdk1.7.0_25\jre
sun.java.command=com.techemet.client.ClientMain
java.specification.vendor=Oracle Corporation
user.language=en
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode
java.version=1.7.0_25
java.ext.dirs=D:\Program Files\Java\jdk1.7.0_25\jre...
sun.boot.class.path=D:\Program Files\Java\jdk1.7.0_25\jre...
java.vendor=Oracle Corporation
file.separator=\
java.vendor.url.bug=http://bugreport.sun.com/bugreport/
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.desktop=windows
sun.cpu.isalist=amd64

1 个答案:

答案 0 :(得分:1)

Sun的bug JDK-4417798文档(您在上次评论中提到的文档)描述了捕获异常的方法。引自文件:

public class BugHandler {
    public void handle(Throwable throwable) {
        if (e instanceof ArrayIndexOutOfBoundsException) {
           StackTraceElement[] trace = e.getStackTrace();

           if (trace.length > 1 
               && trace[0].getClassName().equals("sun.awt.Win32GraphicsEnvironment")
               && trace[0].getMethodName().equals("getDefaultScreenDevice")) {
              your_code_to_handle_exception();               
           }
        } 
    }
}

它还建议将-Dsun.java2d.noddraw选项设置为true。根据此other document,它禁用我们使用DirectDraw和Direct3D 。看看是否有帮助。

您还可以尝试强制应用程序在特定屏幕上运行,而不是依赖Java自动检测图形环境。有一个相关的例子使用API documentation中的 GraphicsDevice类