3

ArrayIndexOutOfBounds当我使用 Windows 远程桌面连接到运行我的应用程序的 PC 时,我的 Swing 应用程序似乎抛出异常。知道可能是什么原因造成的吗?

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
4

1 回答 1

1

Sun 的错误 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. 根据this other document,它禁用了我们对 DirectDraw 和 Direct3D 的使用。看看是否有帮助。

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

于 2013-10-31T23:34:50.683 回答