0

I'm new to Java and I have to create a value object, (maybe it's called mapped object in Java) but my code doesn't seem to work, here is the value object:

package ....;

public class User {
    private int id;    
    private int uid;    
    private String name;

    public User()
    {
        // do something here
    }
}

and I assign a new value object like this:

public boolean some_function() 
{               
    User u = new User();

    return true; // got a breakpoint here
}

So if I comment out "User u = new User();" I will go to the breakpoint but if I keep it like above it will just stop running.

On a side note, I keep both the files in the same folder so eclipse doesn't import the file, is this correct or should I import it?

EDIT:

After some time I found out that I had to import the file manually, I thought I tried that but apparently I didn't.

1
  • 3
    You are not providing enough details to say anything. What do you mean mean by stop running? Can you see any error? What are you doing in the User() constructor? Please clarify. Commented Nov 23, 2009 at 15:31

4 Answers 4

1

Dennis, if the code as you posted it is the exact code you're running, then this makes no sense -- the "User u = new User();" call would return you a new User object without any issues, since your constructor is empty.

To demonstrate that to yourself, change your constructor to:

public User() {
  System.out.println("I'm inside the User constructor!");
}

and call your some_function() function again. You should see that line printed out to your console.

Given what you're reporting and the code you're showing, I suspect that the class that contains some_function() isn't "seeing" the User class -- you're importing some other User class rather than the one you created. Are the two classes -- the User class and the class which contains some_function() -- in the same package? If not, what import statement at the top of the some_function()-containing class is handling the import of your User class?

Sign up to request clarification or add additional context in comments.

Comments

0

Sure you don't have an infinite loop in your User() constructor?

Comments

0

Put some code into the constructor, for example

id = 99;

set a break point there.

I don't understand what you mean about importing into Eclipse - I have all my code in Eclipse - however I suspect that your application is not correctly seeing the User class. Maybe you are even getting a compilation error. Create your packages and classes in Eclipse, let it sort out the directories for you.

Show us the whole app class , including the import of User.

Comments

0

Put the breakpoint on User u = new User(); and step into the constructor to see what it's doing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.