Reputation: 583
First timer here on StackOverflow. I have a question concerning req.getParamter. I have a class Alumni(). Within this Alumni class I have a PersonalAddress class that is used to store things like the city, state, street, etc. As im pulling data out of my JSP page I'm running into an error when I try to pull data into the structs. An example may explain better.
public Alumni() {
String name;
int age;
PersonalAddress personaladdress;
public Alumni(){}
... (constuctors,getters and setters within each class, yadda yadda)
}
In my doPost, variables like name are being pulled fine from the html page. Example:
Alumni a = new Alumni();
a.setName(req.getParameter("name"));
But once I get to the "structs" it will not let me do so. Example
a.personaladdress.setStreet(req.getParameter("street"));
Any ideas why I'm not allowed to use getParameter("street") in my personaladdress struct?
Upvotes: 1
Views: 159
Reputation: 6682
I'll try and answer with some questions =)
If it's neither of the above and you're seeing a NullPointerException then it's probably because you've not created the PersonalAddress in the new Alumni before trying to set the street (which you can do without the getter syntax).
Alumni a = new Alumni();
a.setPersonalAddress(new PersonalAddress();
a.personalAddress.street(req.getParameter("street"));
Upvotes: 1