new JFileChooser()遭遇AssertionError的解决方案

背景说明

今天在运行自己早前写的一个Swing应用程序时,在一个打开文件对话框的功能莫名其妙的遭遇java.lang.RuntimeException: java.lang.AssertionError。这是个断言错误,以前没有遇到过,一时搞不清楚状态。

具体报错信息如下,在语句new JFileChooser()出触发:

java.lang.RuntimeException: java.lang.AssertionError
    at java.beans.EventHandler.invokeInternal(EventHandler.java:489)
    at java.beans.EventHandler.access$000(EventHandler.java:279)
    at java.beans.EventHandler$1.run(EventHandler.java:430)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.beans.EventHandler.invoke(EventHandler.java:428)
    at com.sun.proxy.$Proxy0.actionPerformed(Unknown Source)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
    at java.awt.Component.processMouseEvent(Component.java:6525)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6290)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2739)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:719)
    at java.awt.EventQueue$4.run(EventQueue.java:717)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.AssertionError
    at sun.awt.shell.Win32ShellFolder2$4.call(Win32ShellFolder2.java:400)
    at sun.awt.shell.Win32ShellFolder2$4.call(Win32ShellFolder2.java:398)
    at sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Win32ShellFolderManager2.java:535)
    at sun.awt.shell.ShellFolder.invoke(ShellFolder.java:518)
    at sun.awt.shell.Win32ShellFolder2.getIShellFolder(Win32ShellFolder2.java:398)
    at sun.awt.shell.Win32ShellFolder2.access$200(Win32ShellFolder2.java:72)
    at sun.awt.shell.Win32ShellFolder2$2.call(Win32ShellFolder2.java:298)
    at sun.awt.shell.Win32ShellFolder2$2.call(Win32ShellFolder2.java:296)
    at sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Win32ShellFolderManager2.java:535)
    at sun.awt.shell.ShellFolder.invoke(ShellFolder.java:518)
    at sun.awt.shell.Win32ShellFolder2.<init>(Win32ShellFolder2.java:296)
    at sun.awt.shell.Win32ShellFolderManager2.createShellFolderFromRelativePIDL(Win32ShellFolderManager2.java:95)
    at sun.awt.shell.Win32ShellFolder2$11.call(Win32ShellFolder2.java:819)
    at sun.awt.shell.Win32ShellFolder2$11.call(Win32ShellFolder2.java:807)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Win32ShellFolderManager2.java:511)
    at java.lang.Thread.run(Thread.java:745)

解决方案(也就是问题原因)

经过在Bing上面的搜索,找到相关英文资料(百度上面没有查找到相关信息)。

最后的解决方案是:禁用JVM的-esa参数设置(Disable assertions by removing -esa virtual machine argument.)

-enableassertions[:<package name>"..." | :<class name> ]
-ea[:<package name>"..." | :<class name> ]
上述参数就用来设置JVM是否启动断言机制(从JDK1.4开始支持),缺省时JVM关闭断言机制。用-ea可打开断言机制,不加<packagename>和classname时运行所有包和类中的断言,如果希望只运行某些包或类中的断言,可将包名或类名加到-ea之后。例如要启动包com.wombat.fruitbat中的断言,可用命令java -ea:com.wombat.fruitbat...<Main Class>

-enablesystemassertions
-esa
激活系统类的断言。

然后我就回到Netbeans中查看该工程的运行参数,还真设置了-ea -esa,但是我完全不知道是什么时候设置上的,肯定不是我自己设置的。移除掉VM选项中的内容即可正常运行了。
Netbeans工程配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值