Link to home
Create AccountLog in
Avatar of ibanja
ibanja

asked on

Eclipse Java--Scrapbook error: cannot be resolved to a type

Eclipse 3.2 Linux

I am learning Java and Eclipse from a tutorial called "Eclipse and Java for Total Beginners" located at http://eclipsetutorial.sourceforge.net/totalbeginner.html.

When I got to the Junit testing lesson I couldn't use my Crtl+Space (auto-completion). To fix it, I deleted a directory called Default. That fixed it, but now my Scrapbook is having the same problem.

Basically, it can't find my class.
Example:
 
Person cannot be resolved to a type
Person cannot be resolved to a type
Person p = new Person();
p.setName("Fred");
p.toString()

Open in new window


Lines 1 and 2 are the errors I get when running "Inspect".
Attached is a snapshot of my Eclipse project tree.

Does anyone know how to get this fixed?

Thanks,
Frank User generated image
Avatar of __geof__
__geof__
Flag of Norway image

The Person class is not visible to this code. Are you sure the spelling is correct and the Person class is imported?
Eventually post your code to help finding out.
Avatar of ibanja
ibanja

ASKER

Here is my Person.java file:

 
package org.totalbeginner.tutorial;
public class Person {

        //       fields
    private String name;
    private int maximumBooks;

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

    }

    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;
    }
    
    
}

Open in new window

And the class were the error is coming from?
Avatar of ibanja

ASKER

The Person class.  It's the only thing I've coded so far.
how do you run it to get the error?
It says p.setName("Fred") but it is nowhere in your code...
Avatar of ibanja

ASKER

I highlight the code in scrapbook and then run "inspect" from within eclipse.  I'm pretty sure it's and Eclipse issue, because it worked before.

The class:
public void setName(String anyName)
    {
            name = anyName;
    }
ASKER CERTIFIED SOLUTION
Avatar of __geof__
__geof__
Flag of Norway image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of ibanja

ASKER

__geof__:

Thanks for the response. I had an emergency last week and couldn't get back to this until now.

I made a new directory called "newtotalBeginner."
Opened Eclipse and selected that as my new workspace.
Created a new project named "TotalBeginner."
When I selected "import" the choices were:
General
C/C++
CVS
Plug-in Development
Team

I choose General ==> File system
then I imported the directory of my old project.

That didn't work.

Should I be importing the whole directory?  I also tried without the .metadata file, as well as just the src directory, but that didn't help.

The one you want is called import project into workspace. I think it is under general.
Avatar of ibanja

ASKER

That's not working either... don't know what's going on, but looks like I need to start from scratch. That's not a big deal as there isn't much started, but I wanted to know what was happening in case it happens again.

Thanks
Avatar of ibanja

ASKER

Since I can't import a whole project... How do I import a file?  I tried and I am having the same problem.
You need to create a new Java project -> right click on it -> import -> general -> files
Avatar of ibanja

ASKER

I don't have the "File" option, just "File System" which didn't work.  

Avatar of ibanja

ASKER

I'm writing this problem off and moving on.  

Thanks for the help.
Avatar of mrcoffee365
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.