I am trying to create a simple Java console application that requires users to select files from their local file system.
The console will prompt the user to select one of the available options, and then enable the entered input.
public Client() throws UnknownHostException, IOException { printuseroptions(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char userdecision = br.readLine().charAt(0); System.out.println(userdecision); switch(userdecision){ case '1': System.out.println("Which file would you like to open?"); openfile(br.readLine()); break; case '2': System.out.println("Which file would you like to close?"); closefile(br.readLine()); break; } private boolean openfile(String path){ System.out.println("openfile("+path+")"); return false; } private boolean closefile(String path){ System.out.println("closefile("+path+")"); new JFileChooser().showOpenDialog(null); return false; }
No matter what I do, the JFileChooser popup does not open. The error is not displayed on the console, but the debug step shows the following error:
Blockquote Theme [Home] (Paused)
Class NotFoundException (Throwable). (String, Throwable): 217
Class NotFoundException (Exception). (String, Throwable) String: Not available String of class ClassNotFoundException. (String): not available
URLClassLoader $ 1.run (): not available
AccessController.doPrivileged (PrivilegedExceptionAction, AccessControlContext): not available [native method]
Launcher $ ExtClassLoader (URLClassLoader) .findClass (string): not available
Launcher $ ExtClassLoader.findClass (string): not available
Launcher $ ExtClassLoader (ClassLoader) .loadClass (String, boolean) string: not available Launcher $ AppClassLoader (ClassLoader) .loadClass (String, boolean) string: not available Launcher $ AppClassLoader.loadClass (string, logical string): not available
Launcher $ AppClassLoader (ClassLoader) .loadClass (String): not available
ResourceBundle $ RBClassLoader.loadClass (string): not available
CoreResourceBundleControl (ResourceBundle $ Control) .newBundle (String, Locale, String, ClassLoader, boolean): not available
ResourceBundle.loadBundle (CacheKey, List, Control, boolean): not available ResourceBundle.findBundle (CacheKey, List, List, int, Control, ResourceBundle): not available
ResourceBundle.getBundleImpl (String, Locale, ClassLoader, ResourceBundle $ Control): not available
ResourceBundle.getBundle (String, ResourceBundle $ Control): not available
Toolkit $ 3.run () string: not available AccessController.doPrivileged (PrivilegedAction): not available [native method]
Toolkit. (): Not available
Component. (): Not Available
Version Client.closefile (): 90 Client. (): 60
Client.main (String []): 36
The same code works fine on a 32-bit Linux machine, so I suspect the problem is with Windows.
The code below works on both Windows and Linux, so I suspect this is due to various ways, while console input is processed on Windows vs Linux (CR LF).
import javax.swing.JFileChooser; public class Example { public static void main(String[] args) { new JFileChooser().showOpenDialog(null); } }
thanks
java windows-7 64bit jfilechooser
jmccrohan
source share