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

2nd Jul 2019, 5:36 AM
Code Babylon
Code Babylon - avatar
20 Réponses
0
whats the warning ? it should appear before or after those statements.
2nd Jul 2019, 5:46 AM
Taste
Taste - avatar
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.
2nd Jul 2019, 6:49 AM
Code Babylon
Code Babylon - avatar
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
2nd Jul 2019, 6:56 AM
Taste
Taste - avatar
0
Taste How would you close Scanner in this case? I'm new to Java, so I'm still learning the ropes for it.
2nd Jul 2019, 6:58 AM
Code Babylon
Code Babylon - avatar
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(); }
2nd Jul 2019, 7:04 AM
Taste
Taste - avatar
0
Taste And I just replace the current Scanner code with that?
2nd Jul 2019, 7:05 AM
Code Babylon
Code Babylon - avatar
0
yes,
2nd Jul 2019, 7:07 AM
Taste
Taste - avatar
0
Taste I tried replacing the code, but it didn't work, though it might have been that I replaced it incorrectly.
2nd Jul 2019, 4:24 PM
Code Babylon
Code Babylon - avatar
0
the warning still appear or the code didnt work at all ?
2nd Jul 2019, 4:26 PM
Taste
Taste - avatar
0
Taste The code didn't work.
2nd Jul 2019, 4:29 PM
Code Babylon
Code Babylon - avatar
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
2nd Jul 2019, 4:31 PM
Taste
Taste - avatar
0
Taste That does work, but like with the previous code, sc isn't closed
2nd Jul 2019, 4:46 PM
Code Babylon
Code Babylon - avatar
0
try with resource will automaticly close it.
2nd Jul 2019, 4:47 PM
Taste
Taste - avatar
0
Taste What do you mean by "resource"?
2nd Jul 2019, 4:49 PM
Code Babylon
Code Babylon - avatar
0
the try(Scanner sc ) thing. here the scanner is the resource.
2nd Jul 2019, 4:50 PM
Taste
Taste - avatar
0
Taste I'm sorry, but I don't understand.
2nd Jul 2019, 4:52 PM
Code Babylon
Code Babylon - avatar
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();
2nd Jul 2019, 4:53 PM
Taste
Taste - avatar
0
Taste That did work, thank you. However, I still can't get the .exe file to load.
2nd Jul 2019, 5:19 PM
Code Babylon
Code Babylon - avatar
0
did the jar file work ?
2nd Jul 2019, 5:43 PM
Taste
Taste - avatar
0
Taste It did. Or rather, it loaded but now of course it won't open when I test it.
2nd Jul 2019, 5:48 PM
Code Babylon
Code Babylon - avatar