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 15 of 15

Thread: Very Beginner...very frustrated...

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Very Beginner...very frustrated...

    Okay so I am in an online class, and at this point I really regret it. There isn't any teaching, just a book an assignment and go. And this stuff is just not working out for me. This week we are suppose to be working with objects. I am suppose to make a class animal, and then three objects; cat, dog, lion. And when I read it in the text book or the other book I bought or online it makes sense, but every single time I try to compile it I get the cannot find symbol error. Several times I have copied the example directly from the book and still get the error.

    So here is the example from the book:

    class Dog {
    int size;
    String breed;
    String name;

    void bark() {
    System.out.println("Ruff!");
    }
    }


    class DogTestDrive {
    public static void main (String[] args) {
    Dog d = newDog();
    d.size = 40;
    d.bark();
    }
    }

    This is right out of the book I bought but when I type it up I get an error for the newDog(). Can anyone please explain to me why? I thought maybe since they are different things they needed to be in different files, that didn't work so I put them back on the same file...that didnt work either. Whoever helps me with this will by my hero for a long long time.

    Thanks,


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Very Beginner...very frustrated...

    get the cannot find symbol error.
    Please copy the full text of the error messages and paste it here.
    The compiler can not find the definiton for the symbol shown in the error message. Java is case sensitive. Check the spellings to make sure they are correct.

    get an error for the newDog().
    You probably mean to use the new statement (new Dog()) and not to call the newDog() method .
    Last edited by Norm; February 6th, 2013 at 08:28 PM. Reason: correction
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Very Beginner...very frustrated...

    Quote Originally Posted by Norm View Post
    Please copy the full text of the error messages and paste it here.
    The compiler can not find the definiton for the symbol shown in the error message. Java is case sensitive. Check the spellings to make sure they are correct.


    You probably mean to use the new statement (new Dog()) and not to create an instance of the newDog class.
    well I don't know how to copy past from Command Prompt so Ill type it out (I know Im new) so Ill type it out.

    DogTestDrive.java:3: error: cannot find symbol
    Dog d = newDog(); \\and there is a little arrow under the "n" in new.

    symbol: method newDog()
    location: class DogTestDrive
    1 error

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Very Beginner...very frustrated...

    Did you read my post about what the problem was and how to fix it?

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Very Beginner...very frustrated...

    Yes I did. What is confusing me though is that the book says that line is "making a dog object" I typed it exactly how the book has it.

    because if I am not mistaken I dont want a statement or a method right? My intent was to make a dog object.


    BTW seriously thanks for helping me.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Very Beginner...very frustrated...

    make a dog object.
    You use the new statement to create an instance of an object.

    See the tutorial:
    Creating Objects (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Very Beginner...very frustrated...

    Well I did think about what you said and changed my homework. I declared the objects in the animal class and then when I called the instance of that object it work!!! Seriously Awesome. I am halfway done with this class so I am sure I will be back soon...but thank you very much...you saved me from pulling all of my hair out.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Very Beginner...very frustrated...

    Hope it gets clearer soon.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Very Beginner...very frustrated...

    Ah well I know you just finished helping me but now I am having another problem. Below is the actual hellish homework assignment. It compiles fine now thanks to your help. However now when I try to actually run it I get an error saying "Error: Main method not found in class Animal, please define the main method as: public static void main(String[] args)

    However if I understand it the main method should be called in the DemoAnimal class because that is the class actually executing the speak() and attack() methods. Any guidance would be greatly appreciated.



    class Animal {

    Animal cat;
    Animal dog;
    Animal lion;

    void speak() {
    System.out.println("Noise");
    }
    void attack() {
    System.out.println("attack");
    }



    }
    class Cat extends Animal {

    void speak() {
    System.out.println("Meow");
    }
    }

    class DemoAnimal extends Animal {
    public void main (String args[]) {

    Cat subcat = new Cat();
    }
    }

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Very Beginner...very frustrated...

    The java command requires a main() method as described in the error message in the class that is used on the command line with the java command. For example
    java TheClass

    TheClass is the starting class and must have a main() method.

    See the tutorial:
    "Hello World!" for Microsoft Windows (The Java™ Tutorials > Getting Started > The "Hello World!" Application)

    I'm done for tonight. Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Very Beginner...very frustrated...

    That did help. Thank you again.

  12. #12
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Very Beginner...very frustrated...

    Okay hopefully this is the last time I need to ask a question...at least for this assignment. I have an Animal class and then a dog, cat, and lion subclass. My main class is DemoAnimal. Everything compiles without error except the DemoAnimal. For all I can see I am writing the code just like the books and websites tell me to. However I keep getting four "Cannot find symbol" errors when I try to compile it. I no longer get all the other errors I was getting so I am making real progress. But I think my problem is I am honestly not understanding what I am typing. Below is my code.

    class DemoAnimal {
    public static void main (String args[]) {
    animalTest animal = new Animal();
    Cat subcat = new Cat();
    Dog subdog = new Dog();
    Lion sublion = new Lion();
    s = Cat;
    s.speak();
    }
    }


    Now if I understand right, the third line initiates the Animal class I created, and the following three initiate the subclasses I created. s = Cat; seems wrong to me since it seems I am making another reference for cat that I have already initiated. But it seems to be written that way in my text book and its confusing the hell out of me. Below are my errors when I compile.


    c:\myjava\animal>javac DemoAnimal.java
    DemoAnimal.java:3: error: cannot find symbol
    animalTest animal = new Animal();
    ^
    symbol: class animalTest
    location: class DemoAnimal
    DemoAnimal.java:7: error: cannot find symbol
    s = Cat;
    ^
    symbol: variable s
    location: class DemoAnimal
    DemoAnimal.java:7: error: cannot find symbol
    s = Cat;
    ^
    symbol: variable Cat
    location: class DemoAnimal
    DemoAnimal.java:8: error: cannot find symbol
    s.speak();
    ^
    symbol: variable s
    location: class DemoAnimal
    4 errors

    This forum has been amazingly helpful so far and I would really appreciate someone explaining what I am doing wrong.

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Very Beginner...very frustrated...

    When the compiler says: cannot find symbol that means it can not find a definition for the symbol in the error message.
    Look at the error message, get the symbol mentioned in the message and see why the compiler can not find it.
    Some of the Possibilities: misspelling; there is no definition; the method or constructor takes different args than given
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Very Beginner...very frustrated...

    Hey just wanted to say I was able to get my little homework program to function correctly. I did a happy dance. Wanted to say thanks again for your help.

  15. #15
    Junior Member Fabgio's Avatar
    Join Date
    Feb 2013
    Location
    Padua, Italy
    Posts
    8
    My Mood
    Fine
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Very Beginner...very frustrated...

    First and foremost you need to define the s symbol. It could be an instance variable or an object. If s were a cat type object you should define a "Cat" class. Therefore the s object would be an instance of the "Cat" class:
    class Cat {
       type speak() {
             //...body of speak method
       }
    }
    class DemoAnimal  {
           public static void main (String args[]) {
           Cat s=new Cat();
           s.speak();
          //.... 
       }
    }

Similar Threads

  1. Beginner help please.
    By xdorkiee in forum What's Wrong With My Code?
    Replies: 59
    Last Post: December 20th, 2012, 09:19 PM
  2. hello... i am a beginner...
    By learningjava1 in forum Member Introductions
    Replies: 1
    Last Post: November 24th, 2012, 12:19 PM
  3. Beginner
    By mkarthik90 in forum Member Introductions
    Replies: 1
    Last Post: February 18th, 2012, 02:26 PM
  4. Beginner
    By angelo24 in forum Member Introductions
    Replies: 1
    Last Post: August 19th, 2011, 07:14 AM
  5. Frustrated lol.
    By stealthmonkey in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 14th, 2010, 10:02 PM