• Post Reply Bookmark Topic Watch Topic
  • New Topic

my first bean!!!  RSS feed

 
Sam Anjos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created the following bean with NetBeans IDE I keep getting a "Exception in thread 'main'" error.
public class User{

protected String lastName;
protected String firstName;

public String getLastName(){
return lastName;
}

public void setLastName (String lname){
lastName = lname;
}
public String getFirstName(){
return firstName;
}
public void setFirstName (String firstName){
firstName = firstName;
}
}
I would like to eventually call the bean from a jsp file but I don't see anything wrong with this bean or i am just that blind
Any help would be appreciated.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Three things...
1) Thanks for joining JavaRanch, but could you take a quick look at the naming policy and edit your profile accordingly.
2) There is a difference between JavaBeans and Enterprise JavaBeans. This forum is for the latter. In the future I suggest you post questions like these in the JiG Forums, you will get a better response there.
3) Your problem is in the setFirstName() method. You are overshadowing your firstName variable and never really setting it. The correct code would make use of the this keyword.

[ June 17, 2003: Message edited by: Chris Mathews ]
 
Sami Casab
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your main method?
Are you creating a new instance?
 
Sam Anjos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To my understanding I don't need a main method in a JavaBean.
Regarding the "this" it doesn't work either.... I'm guessing could it be becuase the javaBean doesn't like to be run?
P.S Sorry Chris for my newbie ways.. your advise has been taken.
Sam
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!