Menu

Question on Lesson 3

Mike
2007-09-02
2013-10-06
  • Mike

    Mike - 2007-09-02

    Hi Mark, first of all I just wanted commend you on the great job you did on these tutorials.  Every lesson has the right amount of information and is well-paced.

    I've been following your examples word-by-word until Lesson 3 where you are using the scrapbook to inspect the object "p".  After creating the new object, I tried to invoke the set functions, but received the error message "The method setName(String) or setMaximumBooks(int) is undefined for the type Person".  I'm not sure what the problem is but maybe I forgot to include something?

    Thanks

     
    • Mike

      Mike - 2007-09-02

      Hi Mark,

      After playing around with it for awhile, I think I was able to fix the problem by placing a semicolon after the closing curly braces of the Person class declaration.  I'm not sure if you had to do this too?

      Thanks

       
    • Mark Dexter

      Mark Dexter - 2007-09-02

      Hi Mike. Please look in the Companion Document, on page 13. You will see the code snapshot called "Lesson 2 -- Person Class (with get and set methods)".  This has the methods that were added in during lesson 2. It sounds like one or both of those methods aren't in your Person file. So just compare the code snapshot to your Person class and you should be able to see what is wrong. You can also copy and paste from the PDF into the Person file if you need to. Let me know what you find out. Thanks. Mark Dexter

       
    • Mike

      Mike - 2007-09-02

      Hi Mark,
      I checked over my Person.java file with yours word for word and still couldn't find any discrepancies.  However, after I added a semicolon after the closing curly brace for the class declaration, the problem went away.

       
    • Mark Dexter

      Mark Dexter - 2007-09-03

      Hi Mike. That doesn't make much sense to me. Normally, you don't put anything after the closing "}" of a class. It sounds like you might have something else going on. If you like, you could post a copy of the source code of the Person.java file and I would be happy to look at it. Mark

       
  • Denis Lozhkin

    Denis Lozhkin - 2010-10-18

    I've done this and I still have the same problem

     
  • Dirk Young

    Dirk Young - 2010-10-20

    I am having the same problem.

     
  • Gill

    Gill - 2010-10-23

    I am having the exact same problem, Lesson 3 (9:25)

    Person.java is identical to that in the lesson and I have follwed this several times now with no change.

    I get "The method setName(String) is undefined for the type Person" every time I inspect.

    Using  Eclipse Platform Version: 3.3.2

     
  • Gill

    Gill - 2010-10-23

    All fixed now, had other java programmes on PC.

    Set Eclipse as main default for .java files and it works great now!!!!

     
  • Ally

    Ally - 2010-10-26

    I am having the exact same problem. Here is the code:

    package org.totalbeginner.tutorial;

    public class Person
    {
    //fields
    private String name; //name of the person
    private int maximumBooks; // most books person can check out

    // constructors
    public Person()
    {
    name = "unknown name";
    maximumBooks = 3;
    }

    // methods
    public String getName()
    {
    return name;
    }

    public void setName(String anyName)
    {
    name = anyName;
    }

    public int getMaximumBooks()
    {
    return maximumBooks;
    }

    public void setMaximumBooks(int maximumBooks)
    {
    this.maximumBooks = maximumBooks;
    }
    }

    The method setName(String) is undefined for the type Person
    Person p = new Person();
    p.setName("Fred");
    p

     
  • Ally

    Ally - 2010-10-26

    Incidentally, I get the same error when trying the setMaximumBooks method as well.

     
  • Ally

    Ally - 2010-10-26

    OK, when I put the

    Person p = new Person();

    and the the "p" after it, the inspector returns this:

    But once I try putting in the methods, I get the error.

     
  • Ally

    Ally - 2010-10-26

    I found the issue. I have more than one hard drive in my computer. Your workstation needs to be on the same drive off of which Eclipse is running. I simply moved my workspace to the same drive, and it functions just fine.

     
  • cj windex

    cj windex - 2010-11-19

    I am having the same problem.

    The method setName(String) is undefined for the type Person
    Person p = new Person();
    p.setName("Fred");
    p

    I have everything saved in the same place. I am not sure what is wrong. Here is my coding.

    package org.totalbeginner.tutorial;

    public class Person
    {
    //fields
    private String name; //name of the person
    private int maximumBooks; // most books person can check out

    // constructors
    public Person()
    {
    name = "unknown name";
    maximumBooks = 3;
    }

    // methods
    public String getName()
    {
    return name;
    }

    public void setName(String anyName)
    {
    name = anyName;
    }

    public int getMaximumBooks()
    {
    return maximumBooks;
    }

    public void setMaximumBooks(int maximumBooks)
    {
    this.maximumBooks = maximumBooks;
    }
    }

     
  • temp99878

    temp99878 - 2011-07-27

    I had to do the same here to remove the error:
    " Set Eclipse as main default for .java files and it works great now"

     
  • Collin Crowther

    Collin Crowther - 2011-08-05

    How do you "Set Eclipse as main default for .java files" ??

    Thank you!

     
  • Collin Crowther

    Collin Crowther - 2011-08-05

    Figured it out.  When you set up a new project make sure you check the Use Default JRE which in my case was the new jdk1.7.0 in the JRE section.  I was using the wrong JRE.

     
  • Trevor

    Trevor - 2011-08-10

    If you are using a Mac - DONT select the default JRE (which is Macs OSX version), when creating the project, select 'Use and execution environment JRE'  (in my case it shows JavaSE-1.6 which came with the Eclipse install) - it now works fine on my Mac..

     
  • Mike McGuire

    Mike McGuire - 2013-10-06

    Trevor's tip works. I installed 1.7 on my MacBook and also did the following trick, which I found when searching about how to set up Eclipse on a Mac (http://stackoverflow.com/questions/14341865/how-to-install-jre-1-7-on-mac-os-x-and-use-it-with-eclipse):

    You need to tell Eclipse which JDK/JRE's you have installed and where they are located.

    This is somewhat burried in the Eclipse preferences: In the Window-Menu select "Preferences". In the Preferences Tree, open the Node "Java" and select "Installed JRE's". Then click on the "Add"-Button in the Panel and select "Standard VM", "Next" and for "JRE Home" click on the "Directory"-Button and select the top level folder of the JDK you want to add.

    /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.