Results 1 to 8 of 8
- 03-28-2012, 03:44 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
The method setName(String) is undefined for the type Person
Hi I've run into a problem that shouldn't be happening. I'm on the third video tutorial from the eclipse website.
I have created a simple class called Person:
Take note of the setName method, that's where the problem is. I open the scrapbook to learn a bit about that next. I clicked the Import Declarations button and added the org.totalbeginner.tutorial package. I followed the tutorial exactly, that method IS defined in the Person class.Java Code:package org.totalbeginner.tutorial; public class Person { // fields private String name; // name of person private int maximumBooks; // the most books a person can check out // constructor 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; } }
Into the scrapbook I type:
Which leads to the message:Java Code:Person p = new Person(); p.setName("Fred"); p
Why is Eclipse doing this to me?The method setName(String) is undefined for the type Person
- 03-28-2012, 04:06 PM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: The method setName(String) is undefined for the type Person
What is this scrapbook? Is it an environment for testing some code? Maybe the Person object know by this scrapbook is different to what you have in your Eclipse. Have you tried to recompile it so both of them refer to the same Person class? Because the code looked just fine.
Website: Learn Java by Examples
- 03-28-2012, 04:10 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Re: The method setName(String) is undefined for the type Person
I have some more information. For some reason Eclipse seems to think that the Person class is not a part of my current project. I tried to create a new Junit Test Case thingy and calling it PersonTest to test the Person class. However it complained that the Person class wasn't a part of this current project.
A look at my screen may help:
- 03-28-2012, 04:14 PM #4
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Re: The method setName(String) is undefined for the type Person
I've tried to make it point to the same Person class, it should be pointing to it anyway as one step I took was to make sure that doesn't happen (I clicked the Import Declarations button and added the org.totalbeginner.tutorial package.). I tried using "org.totalbeginner.tutorials.Person" but I get the exact same message.
And yes the Scrapbook is for testing code snippets.
- 03-28-2012, 04:19 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,467
- Rep Power
- 16
Re: The method setName(String) is undefined for the type Person
That Person class in that screenshot hasn't been saved (it has an '*' next to it), so it hasn't been compiled.
Not that that is necessarily your problem, but you never know.Please do not ask for code as refusal often offends.
- 03-28-2012, 04:38 PM #6
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Re: The method setName(String) is undefined for the type Person
Thanks Tolls, that solved the problem with the scrapbook. Gotta remember things need saving.
My problem with the Test Case I solved too, take a look at the screenshot I misspelled the highlighted package name to the left :/
Thanks
- 03-29-2012, 06:05 AM #7
Re: The method setName(String) is undefined for the type Person
This thread is more suited to the Eclipse forum than New to Java. Moving.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-29-2012, 09:26 AM #8
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Similar Threads
-
operator undefined for argument type int, String
By aconti in forum New To JavaReplies: 8Last Post: 05-30-2011, 07:32 AM -
Error: "The method startsWith(String, String) is undefined for the type StringUtils"
By shihad_s in forum New To JavaReplies: 10Last Post: 12-07-2010, 12:29 PM -
The method myFunction(String) is undefined for the type
By jfill in forum New To JavaReplies: 2Last Post: 05-07-2010, 11:02 PM -
The constructor Person(String, String, Date) is undefined
By fh84 in forum New To JavaReplies: 7Last Post: 11-03-2009, 02:18 AM -
[SOLVED] [newbie] The method GBC(int, int) is undefined for the type FontFrame
By jon80 in forum New To JavaReplies: 0Last Post: 05-27-2009, 04:39 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks