I am trying to create a simple console based java application, which requires users to select files from their local filesystem.
The console prompts the user to select one of the available options and then switches on the input given.
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 pop up box will not open. No error is shown on the console, but a debug step-through shows the following error:
Blockquote Thread [main] (Suspended)
ClassNotFoundException(Throwable).(String, Throwable) line: 217
ClassNotFoundException(Exception).(String, Throwable) line: not available ClassNotFoundException.(String) line: not available
URLClassLoader$1.run() line: not available
AccessController.doPrivileged(PrivilegedExceptionAction, AccessControlContext) line: not available [native method]
Launcher$ExtClassLoader(URLClassLoader).findClass(String) line: not available
Launcher$ExtClassLoader.findClass(String) line: not available
Launcher$ExtClassLoader(ClassLoader).loadClass(String, boolean) line: not available Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available Launcher$AppClassLoader.loadClass(String, boolean) line: not available
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available
ResourceBundle$RBClassLoader.loadClass(String) line: not available
CoreResourceBundleControl(ResourceBundle$Control).newBundle(String, Locale, String, ClassLoader, boolean) line: not available
ResourceBundle.loadBundle(CacheKey, List, Control, boolean) line: not available ResourceBundle.findBundle(CacheKey, List, List, int, Control, ResourceBundle) line: not available
ResourceBundle.getBundleImpl(String, Locale, ClassLoader, ResourceBundle$Control) line: not available
ResourceBundle.getBundle(String, ResourceBundle$Control) line: not available
Toolkit$3.run() line: not available AccessController.doPrivileged(PrivilegedAction) line: not available [native method]
Toolkit.() line: not available
Component.() line: not available
Client.closefile() line: 90 Client.() line: 60
Client.main(String[]) line: 36
The same code runs perfectly on a Linux 32 bit machine, so I suspect the problem is Windows related.
The code below runs as expected on both Windows and Linux so I suspect might be due to the different ways in while console input is handled in Windows vs Linux (CR LF).
import javax.swing.JFileChooser;
public class Example {
public static void main(String[] args) {
new JFileChooser().showOpenDialog(null);
}
}
Thanks