Results 1 to 7 of 7
  1. #1
    Waarten is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Question Cannot find symbol error

    hi, i'm new to java and working on a assignment for school

    I'm trying to get this piece of code to work:

    Java Code:
    class Vos {
    
    	public int getGegeten() {
    		return 1;
    	}
    	
    	public void resetGegeten() {
    		Vos.getGegeten = 0;
    	}
    }
    The resetGegeten must set the getGegeten to 0, but when I compile this code I get a Cannot find symbol error. Can anybody please help me? Thanks in advance.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Cannot find symbol error

    I get a Cannot find symbol error.
    What symbol and on what line of the program?

    Where is the variable: getGegeten defined?
    The syntax of the statement: Vos.getGegeten
    says that the variable is a static variable in the Vos class.

  3. #3
    Waarten is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: Cannot find symbol error

    javac Vos.java
    Vos.java:7: cannot find symbol
    symbol : variable getGegeten
    location: class Vos
    Vos.getGegeten = 0;
    ^
    1 error

    Vos.java extends Dier.java, Dier.java implents IDier.java

    Vos.java:
    Java Code:
    class Vos extends Dier {
    	public int getGegeten() {
    		return 1;
    	}
    
    	public void resetGegeten() {
    		Vos.getGegeten = 0;
    	}
    }
    Dier.java
    Java Code:
    abstract class Dier implements IDier {
    
    }
    IDier.java
    Java Code:
    public interface IDier {
    
    	public int getGegeten();
    	
    	public void resetGegeten();
    
    }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Cannot find symbol error

    Where is the variable: getGegeten defined?

    I see a method with that name but no variable.

  5. #5
    Waarten is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: Cannot find symbol error

    Isn't that defined in the part?:
    Java Code:
    public int getGegeten() {
            return 1;
        }

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Cannot find symbol error

    Do you know what a variable is?
    What you have posted is the definition of a method.
    You do not assign values to methods. You call them to perhaps do some task and perhaps return a value.
    The method you have posted returns an int with value 1.

    A variable definition starts with a datatype followed by the variable's name:
    String someString ...
    int someInt ...

  7. #7
    Waarten is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: Cannot find symbol error

    ok, I understand it now, thank you for helping

Similar Threads

  1. Cannot Find Symbol error
    By mrgreenacid in forum New To Java
    Replies: 13
    Last Post: 05-16-2011, 08:28 AM
  2. Cannot Find Symbol Error
    By javadummy1 in forum New To Java
    Replies: 6
    Last Post: 04-09-2011, 11:13 AM
  3. Please help- Error: cannot find symbol
    By Avthar in forum New To Java
    Replies: 4
    Last Post: 02-28-2011, 08:34 AM
  4. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  5. Error: cannot find symbol
    By silvia in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:39 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
  •