Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Tolls

Thread: Help with NetBeans Error

  1. #1
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Help with NetBeans Error

    Hi everyone I am creating a program in NetBeans and I am getting the following error:

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: setSecond
    at lab2.Clock.IncrementSecond(Clock.java:68)
    at lab2.ClockTest.main(ClockTest.java:20)
    Java Result: 1


    So in other words it cannot find the symbol: method setSecond (int), method setMinute (int), method setHour (int). I have played around with this for a little while, including trying to instantiate and invoke methods from the class Clock in my main class. Any help would be much appreciated, thanks :)


    Java Code:
    public class Clock {
        private int hr; 
        private int min;    
        private int sec;
        
    public int getHours()
    {
        return hr;
    }
    
    public int getMinutes()
    {
        return min;
    }
    
    public int getSeconds()
    {
        return sec;
    }
    
    public void setClock (int hours, int minutes, int seconds)
    {
        if(0 <= hours && hours < 24) {
            hr = hours;
        }
        else {
            hr = 0;
        }
        if(0 <= minutes && minutes < 60) {
            min = minutes;
        }
        else {
            min = 0;
        }
        if(0 <= seconds && seconds < 60) {
            sec = seconds;
        }
        else {
            sec = 0;
        }
    }
    
    public Clock()
    {
        setClock (0, 0, 0);
    }
    
    public Clock (int hours, int minutes, int seconds)
    {
       setClock (hours, minutes, seconds); 
    
    }
    
    public void IncrementSecond()
    {
        setSecond(sec+1);
        if (sec == 0)
            IncrementMinute();
    }
    
    public void IncrementMinute()
    {
        setMinute(min+1);
        if (min == 0)
            IncrementHour();
    }
    
    public void IncrementHour()
    {
        setHour(hr+1);
    }
    }

    Java Code:
    package lab2;
    
    
    public class ClockTest {
    
       
        public static void main(String[] args) {
            // TODO code application logic here
            {
            Clock setSecond = new Clock();
            setSecond.IncrementSecond();
            
            Clock setMinute = new Clock();
            setMinute.IncrementMinute();
            
            Clock setHour = new Clock();
            setHour.IncrementHour();
            } 
    }
    }

  2. #2
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Help with NetBeans Error

    pretty simple, you need to define a setHour(int) method and a setMinute(int) method as well as a setSecond(int) method.

    you can just say setHour, java doesnt know what that is, but what you can say is:

    Java Code:
    
    public void incrementHour(){
    
    this.setHour(hr+1);
    
    }
    
    public void setHour(int h){
    
    hour = h;
    
    }
    
    
    //even better, just use a increment method it will increase effciency
    
    public void increment hours() {
    
    
    hours += 1;
    
    }

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: Help with NetBeans Error

    Also, don't bother trying to run code that doesn't compile.
    Netbeans highlights problems for you which need to be resolved before you try and run anything.
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,776
    Rep Power
    5

    Default Re: Help with NetBeans Error

    Indeed - you can't run code anyway. You can only run the compiled class file, and code which doesn't compile produces no class file. It doesn't even make sense to try.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: Help with NetBeans Error

    The only reason I ran it was to see if I could find out what the problem was.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help with NetBeans Error

    Quote Originally Posted by gusten View Post
    The only reason I ran it was to see if I could find out what the problem was.
    You shouldn't have ignored the complaints of the compiler in the first place; there is never any need to try to run anything afterwards that was not approved by the compiler.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Error in running netbeans
    By swtjeeva in forum NetBeans
    Replies: 0
    Last Post: 04-08-2012, 04:50 AM
  2. NetBeans - error in code?
    By Sparky in forum NetBeans
    Replies: 4
    Last Post: 02-03-2011, 02:51 AM
  3. Netbeans Error?
    By makpandian in forum NetBeans
    Replies: 3
    Last Post: 05-07-2009, 07:22 AM
  4. Deployment error in Netbeans
    By ruchira mathur in forum NetBeans
    Replies: 1
    Last Post: 01-06-2009, 08:08 AM
  5. NetBeans error
    By michcio in forum New To Java
    Replies: 1
    Last Post: 01-27-2008, 11:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •