1/10 次 java 在 JFileChooser.showOpenDialog 上崩溃
不可重现的崩溃(无错误/异常)。 当我运行一个对话框来选择文件夹时,只有十分之一的时间会发生这种情况。代码:
public String getFilePathFromDialog(String dialogTitle) {
JFileChooser fileChooser;
fileChooser = new JFileChooser();
fileChooser.setDialogTitle(dialogTitle);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setAcceptAllFileFilterUsed(true);
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
return fileChooser.getSelectedFile().toString();
} else {
return "";
}
}
它使我的应用程序崩溃。之后我只能用以下方法关闭它: Ctrl+Alt+删除 ->任务管理器->杀掉它-> 然后我得到“Java(TM) Platform SE 二进制文件没有响应” 然后我点击了“关闭”按钮
我做错了什么还是这是一个错误?
我找到了彼得下面提到的故障转储文件。以下是其中的一些内容:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x62a5ff52, pid=5516, tid=5312
#
# Problematic frame:
# C [nvd3dum.dll+0x2fff52]
#
Current thread (0x04323400): JavaThread "AWT-Windows" daemon [_thread_in_native, id=5312, stack(0x04d60000,0x04db0000)]
siginfo: ExceptionCode=0xc0000005, writing address 0x04ee9004
Non-reproducable crash (no error/exception).
Happens when I run a dialog to select a folder only 1 out of 10 times. Code:
public String getFilePathFromDialog(String dialogTitle) {
JFileChooser fileChooser;
fileChooser = new JFileChooser();
fileChooser.setDialogTitle(dialogTitle);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setAcceptAllFileFilterUsed(true);
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
return fileChooser.getSelectedFile().toString();
} else {
return "";
}
}
It crashes my application. After this I can only close it with:
Ctrl+Alt+Delete -> Task Manager -> Kill it ->
Then I get "Java(TM) Platform SE binary is not responding"
and I hit Close button
Am I doing something wrong or is it a bug?
I found the crash dump file as Peter mentioned below. Here is some of it:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x62a5ff52, pid=5516, tid=5312
#
# Problematic frame:
# C [nvd3dum.dll+0x2fff52]
#
Current thread (0x04323400): JavaThread "AWT-Windows" daemon [_thread_in_native, id=5312, stack(0x04d60000,0x04db0000)]
siginfo: ExceptionCode=0xc0000005, writing address 0x04ee9004
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那是您的 NVidia 视频驱动程序吗?
请注意,这不是在 AWT EDT 线程上,而是在内部系统线程上。您可以尝试禁用 Direct Draw 3D(有一些系统属性可以执行此操作)。
That'll be your NVidia video driver?
Note this is not on the AWT EDT thread, but an internal system thread. You might try disabling Direct Draw 3D (there is some system property for doing that).
当 JVM 运行时非常接近操作系统分配给它的最大内存时,我在 Windows 上看到过类似的情况。然后,用户打开一个对话框(可能在网络驱动器上),这会加载一些额外的操作系统资源(可能是 DLL),然后 JVM 耗尽内存(不是堆,而是分配给 JVM 本身的内存),然后崩溃。
I've seen something like this on Windows when the JVM was running very close the maximum memory allocated allocated to it by the OS. The user then opens a dialog, possibly on a network drive, this loads some additional OS resources (perhaps DLLs), and then the JVM runs out of memory (not heap but memory allocated to the JVM itself) and then crashes.
确保在 EDT 上调用该代码。
另外,只是一个观察(与崩溃无关),最好声明变量 fileChooser 并在同一语句中分配它(不变性):
Make sure that the code is invoked on EDT.
Also, just an observation (nothing to do with the crash), it is better to declare variable fileChooser and assign it in the same statement (immutability):