java - Assigning another class variable value to another class Variable -
i have 2 arrays in 2 different jframes(stores records objects) , haves separate attributes 2 arrays. trying when user enters details in first form , in radio button selection if user selects inpatientcare, open second form , make user enter inpatient care details in form. when user clicks register in inpatient care form , import firstname , last name details user entered in first form , second form put in inpatient care array (2nd array).
i have tried using get/set methods value stored in firstname, error called "exception in thread "awt-eventqueue-0" java.lang.nullpointerexception".
here have done :-
private string firstname; public string getfirstname() { return firstname; }
// have got input through text field in firstname variable havent showed here.
in second form used method , tried assign in variable.
string firstname = patient.getfirstname();
in second form used method value stored in firstname variable, program crashes.
inside first form button register user input through data fields.
private void btnregisterpatientactionperformed(actionevent evt) { firstname=txtfirstname.gettext();
and in radio button selection section if user select inpatient care , click register button in first form , opens second form (inpatient care form).
patient variable object of register new class. made use methods in register_newpatient class.
here initialize patient variable.
jframe frame=new jframe(); register_newpatient patient=new register_newpatient(); static arraylist<patient_class>inpatientpatientlist=new arraylist<patient_class>(); //created seperate array inpatient care. public arraylist<patient_class> getinpatientsarray() //used method return array { return inpatientpatientlist; }
patient null, not firstname. if firstname null method return null without throwing error. if patient null null pointer exception because trying access method (getfirstname()) of null object.
Comments
Post a Comment