Hi guys :)
Well I got an "variable might not have been initialized" error when I tried
to compile the following code:
import java.lang.*;
public class NewFrame {
public static void main(String[] args) {
if (args.length != 3) {
System.out.println("Usage: java NewFrame <frame-name> <frame-hight> <frame-width>");
System.exit(1);
}
int firstArg, secondArg;
try {
firstArg = Integer.parseInt(args[1]);
secondArg = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
System.err.println("Second and third aguments must be integers");
System.exit(1);
}
Simplegui simple = new Simplegui();
simple.setSize(secondArg, firstArg);
simple.setTitle(args[0]);
simple.setVisible(true);
}
}
The error occurs when trying to use the variables firstArg
and secondArg
in line 24.
if I initialize them when I declare them in line 12, It compiles and runs correctly.
So should I just do that? Is this one of the rare times when that is okay or is there some workaround I should know about?
Thanks a bunch in advance :)