0
Java Compile Warnings (Eclipse)
I am trying to export the .java file from the Eclipse IDE and turn that into a .jar file so I can make it an executable file, but whenever I export the .java file I always get this warning: JAR export finished with warnings. See details for additional information. Exported with compile warnings: Number Grow/src/NumberGrow.java Where did I go wrong? https://code.sololearn.com/ctYlWGwCe29s/?ref=app
20 ответов
0
whats the warning ? it should appear before or after those statements.
0
Taste
When I export in Eclipse, the warning is as stated: Number Grow/src/NumberGrow.java
That's it. That's the only thing I get. It still exports, but when I make it into a .exe file, the file doesn't open.
0
the only warning that i could see is Scanner is never closed. but its not really a big problem for a small program, so its kinda okay to ignore the warning.
but the exe part, i'm not sure it might be a different problem
0
Taste
How would you close Scanner in this case? I'm new to Java, so I'm still learning the ropes for it.
0
scanner.close();
or use try with resource.
try (Scanner scan=new Scanner(System.in)){
//you still can use scanner like normal here
x=scan.nextLine();
}
0
Taste
And I just replace the current Scanner code with that?
0
yes,
0
Taste
I tried replacing the code, but it didn't work, though it might have been that I replaced it incorrectly.
0
the warning still appear
or the code didnt work at all ?
0
Taste
The code didn't work.
0
try(Scanner sc = new Scanner(System.in)){
int Number = sc.nextInt();
if(Number >= 2) {
System.out.println("Thank you!");
int x = 1;
while(x > 0) {
System.out.println(x);
x++;
}
} else {
System.out.println("Please try again.");
}
}
it should look like this
0
Taste
That does work, but like with the previous code, sc isn't closed
0
try with resource will automaticly close it.
0
Taste
What do you mean by "resource"?
0
the try(Scanner sc ) thing.
here the scanner is the resource.
0
Taste
I'm sorry, but I don't understand.
0
maybe try this one, we just manually close it
Scanner sc = new Scanner(System.in);
int Number = sc.nextInt();
if(Number >= 2) {
System.out.println("Thank you!");
int x = 1;
while(x > 0) {
System.out.println(x);
x++;
}
} else {
System.out.println("Please try again.");
}
sc.close();
0
Taste
That did work, thank you. However, I still can't get the .exe file to load.
0
did the jar file work ?
0
Taste
It did. Or rather, it loaded but now of course it won't open when I test it.