Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: I have to send this tomorrow and i have now idea what is wrong

  1. #1
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy I have to send this tomorrow and i have now idea what is wrong

    Im very new to java so im sorry if this hurts your eyes.
    So im supposed to make a clock that for 3 minutes after starting the program it prints the time starting from 16:28:58 but i get this message when i run it
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    import java.util.concurrent.TimeUnit;
     
    public class clockApp {
     
     
    		//Data
     
    		private int hours;
    		private int minutes;
    		private int seconds;
     
     
    		// Methods
     
    		void setHour(int h) {
    			hours=h;
     
    		}
     
    		void setMin(int m) {
    			minutes=m;
     
    		}
     
    		void setSec(int s) {
    			seconds=s;
     
    		}
    		void tick() {
    			if (hours==23 && minutes==59 && seconds==59){
    				hours=0;
    				minutes=0;
    				seconds=0;
    			}
    			if (minutes==59 && seconds==59){
    				hours=hours+1;
    				minutes=0;
    				seconds=0;
    			}
    			if (seconds==59){
    				minutes=minutes+1;
    				seconds=0;
    			}
    			else{
    				seconds=seconds+1;
    			}
     
    		}
    		public String toString() {
    			String a=Integer.toString(hours);
    			String b=Integer.toString(minutes);
    			String c=Integer.toString(seconds);
    			string z=a+":"+b+":"+c;
    			return z;
     
    		} 
     
     
     
     
     
    		public static void main (String args[]) throws Exception{
     
    			clockApp idk=new clockApp();
    			idk.setHour(16);
    			idk.setMin(28);
    			idk.setSec(58);
    			for (int i=0;i<181;i++){
    				System.out.println(idk.toString());
    				idk.tick();
    				TimeUnit.SECONDS.sleep(1);
     
     
     
     
     
     
     
     
    			}
    			}
     
     
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    Can you compile the program to get a proper compiler error message?

    Does the error message have a source file line number in it?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    Im sorry i can't find how to upload the image here directly so i will just send you this imgur link.
    https://imgur.com/vX2GtS2

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    Please copy the text of the error message and paste it here. No images
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    My apologies.
    This is the text i get when i run it.

    PS C:\Users\stath> & 'C:\Program Files\Java\jdk-17.0.2\bin\java.exe' '--enable-preview' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'C:\Users\stath\AppData\Local\Temp\vscodesws_6ff27 \jdt_ws\jdt.ls-java-project\bin' 'clockApp'
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at clockApp.main(test 3.java:68)
    PS C:\Users\stath>

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    at clockApp.main(test 3.java:68)
    What code is on line 68?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    its this line.
    public static void main (String args[]) throws Exception{

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    I don't see how the exception would happen on that line.
    Your IDE is hiding the statement where the Unresolved compilation problem is located.
    Can you use the javac command to compile the source code to get a compiler error?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    I tried using the Javac command but it doesn't seem to find my file, I even tried making a new one with notepad and it still didn't recognize it.
    This is the message i get.

    C:\Users\stath\Desktop>javac ClockTest.java
    error: file not found: ClockTest.java
    Usage: javac <options> <source files>
    use --help for a list of possible options

    Again i'm very new to this i'm sorry for the inconvenience.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    C:\Users\stath\Desktop>javac ClockTest.java
    The javac command looks in the current directory for the source file. For the above command it will look in the the Desktop folder.
    Perhaps you need to use the cd command to change directories to be in the directory holding the source file.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    I used cd desktop because my file is in the Desktop folder. But it still didn't recognize it

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    Use the dir command to show what is in a folder.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    I did it and i ran it with javac this is the error i get.

    ClockTest.java.:9: error: class clockApp is public, should be declared in a file named clockApp.java
    public class clockApp {
    ^
    ClockTest.java.:59: error: cannot find symbol
    string z=a+":"+b+":"+c;
    ^
    symbol: class string
    location: class clockApp
    2 errors

    --- Update ---

    I fixed my program!!! Thank you for helping me.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I have to send this tomorrow and i have now idea what is wrong

    Good, I am glad you have found the problem.

    I have never understood why an IDE ignores errors and tries to execute a bad program.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. no idea what is wrong with this code
    By MLG_C00K1E in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 23rd, 2017, 10:15 AM
  2. [SOLVED] Boolean trouble, no idea whats wrong.
    By Cekeh in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 20th, 2013, 07:13 PM
  3. Help! have no idea what's wrong with my code..
    By Zaki in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 17th, 2012, 10:22 PM
  4. Replies: 2
    Last Post: September 2nd, 2012, 02:06 PM
  5. Need help on an Assignment but its due tomorrow!
    By Mob31 in forum Paid Java Projects
    Replies: 1
    Last Post: March 2nd, 2011, 06:54 AM