I have two classes as following
Address
int ID
int unit
String street
User
int ID
String Name
Address address
my user class
public class user{
.....
private Address address;
...getters setters...
}
As shown above User class has an object of Address class in it. My code is expected to receive the values of a form and show them on console.
But when I try to access the unit attribute of address class it shows the following error.
"SEVERE: Exception occurred during processing request: null java.lang.NullPointerException"
my controller
@Action
class myclass implements ModelDriven{
private User user = new User();
public Register(){
System.out.println("User's Unit" + user.getAddress().getUnit()); // error is on this line
}
@Override
public Object getModel() {
return user;
}
jsp file
<s:form action="Register">
<s:textfield name="name" label="Name"/>
<s:textfield name="unit" label="Unit"/>
<s:textfield name="block" label="Block"/>
</s:form>