日期:2014-05-20  浏览次数:20785 次

java真正高手来解答一下,很考技术
在我的Applet中有一个方法open(),在该方法中调用了SelectDir(),我从网页上的一个按钮调用open()时会出现异常。(如下) 请问原因是什么?怎样解决这个问题!
public int open()
  {
  dir = SelectDir();
  if(!dir.equals("SelectDir Cancel")){return 1 ;}
  else{return 0};  
  }

File loction = null; 
public String SelectDir()
  {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  int result = fileChooser.showOpenDialog(this);
  if (result == JFileChooser.CANCEL_OPTION) {
  loction = null;
  return "SelectDir Cancel";
  }
  else {
  loction = fileChooser.getSelectedFile();
  if(loction.isDirectory())
  {
  System.out.println("Dir name is :" + loction.toString());
  }
  return loction.toString() + "\\";
  }
  }

出现的异常报告:
java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation.CallMethod(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(Unknown Source)
... 4 more
Caused by: java.lang.ExceptionInInitializerError
at sun.awt.shell.Win32ShellFolder2$ComTask.execute(Unknown Source)
at sun.awt.shell.Win32ShellFolder2.getFileSystemPath(Unknown Source)
at sun.awt.shell.Win32ShellFolder2.composePathForCsidl(Unknown Source)
at sun.awt.shell.Win32ShellFolder2.<init>(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.getDesktop(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
at sun.awt.shell.ShellFolder.get(Unknown Source)
at javax.swing.filechooser.FileSystemView.getRoots(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI.updateUseShellFolder(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(Unknown Source)
at javax.swing.plaf.basic.BasicFileChooserUI.installUI(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI.installUI(Unknown Source)
at javax.swing.JComponent.setUI(Unknown Source)
at javax.swing.JFileChooser.updateUI(Unknown Source)
at javax.swing.JFileChooser.setup(Unknown Source)
at javax.swing.JFileChooser.<init>(Unknown Source)
at javax.swing.JFileChooser.<init>(Unknown Source)
at AppletTest.SelectDir(AppletTest.java:2678)
at AppletTest.StartToRecord(AppletTest.java:2590)
... 14 more
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission shutdownHooks)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.Runtime.addShutdownHook(Unknown Source)