我刚学习java 为什么我new 一个JFileChooser 就报错啊 求大神给解决 是不文件夹的问题呢报错的代码是:
Exceptioninthread"main"java.lang.RuntimeException:java.io.IOException:Couldnotgetshel...
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Could not get shell folder ID list
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Unknown Source)
at sun.awt.shell.Win32ShellFolder2.getFileSystemPath(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.getPersonal(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$10.call(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$10.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Could not get shell folder ID list
at sun.awt.shell.Win32ShellFolder2.getFileSystemPath0(Native Method)
at sun.awt.shell.Win32ShellFolder2.access$900(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$8.call(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$8.call(Unknown Source)
... 11 more 展开
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Unknown Source)
at sun.awt.shell.Win32ShellFolder2.getFileSystemPath(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.getPersonal(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$10.call(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$10.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Could not get shell folder ID list
at sun.awt.shell.Win32ShellFolder2.getFileSystemPath0(Native Method)
at sun.awt.shell.Win32ShellFolder2.access$900(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$8.call(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$8.call(Unknown Source)
... 11 more 展开
2个回答
展开全部
读写异常啊,是不是你的IO流打开的是一个文件夹,而不是文件
更多追问追答
追问
import javax.swing.JFileChooser;
public class Test2 {
public static void main(String[] args) {
JFileChooser fc=new JFileChooser();
}
}
我的代码是这个 就 new了一下
追答
试试这段代码
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码贴出来看一看
更多追问追答
追问
import javax.swing.JFileChooser;
public class Test2 {
public static void main(String[] args) {
JFileChooser fc=new JFileChooser();
}
}
追答
代码就只有这么多吗?不会报错啊,我把代码放到我的eclipse里面就没有报错,你再看看是不是其他地方出现问题了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询