Why the message appears?
I'm sure the code is OK
com/codegym/task/task07/task0723/Solution.java:12: error: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown
Thread.sleep(100);
public class Solution {
public static void main(String[] args) {
for (int i = 30; i >= 0; i--) {
System.out.println(i);
Thread.sleep(100);
}
System.out.println("Boom!");
}
}
What is wrong
Under discussion
Comments (7)
- Popular
- New
- Old
You must be signed in to leave a comment
ddi
24 June 2019, 13:39
public static void main(String[] args)throws InterruptedException {
You need to write throws InterruptedException for the class to recognize it!
+9
Guadalupe Gagnon
21 January 2019, 18:47
The method Thread.Sleep has an exception that can be thrown. Because of this you either need to surround it in a catch block, or add the exception to your method signature. If you click the part that has the red squiggly in your code (sleep) and hit alt enter, IntelliJ will present you with options to solve (which will be the same i just said).
+7
Niket
4 February 2019, 08:23
How can we surround it with the catch block that you are referring to...?? I am writing the code on the website itself not on IntelliJ
0
Guadalupe Gagnon
4 February 2019, 14:22
you need intelliJ. The website IDE will throw a whole bunch of false errors and provides no help with things like this. It's impressive that you made it this far without it, but you shouldn't even try going further until you download it.
+2
Sokhibjon
28 March 2019, 15:19
search for Thread.sleep example then copy the throws(exception) when you are opening the paren for main method
0
Kent Hervey Software Engineer/Consult Expert
22 November 2019, 05:06
Good advice about InteliJ unless a person is trying to code everywhere and that means iPad, Chromebook, library, friend's house....I can respect that
0
Jeremi Nuer
30 November 2020, 23:57
I would like to use IntelliJ... but it doesn't work for my computer. For some reason, importing the codegym version does not work for me, and doesn't change anything. So I will have to make due with this.
0