0

set/get methods in class "hostel_DtRm" (Acronym for date and room). I make it very simple so you get the point.

public class hostel_DtRm {

private String guests;

// Constructor
public   hostel_DtRm (){}

// Set guests method  
public void setguests(String guests) {
    this.guests=guests;

}
//get guest method
 public String getguests() {
 return guests;
}

Another Class called "LogedInMain", where the set methods from "hostel_DtRm" are populated.

public class LogedInMain {

private hostel_DtRm dtrm;

public LogedInMain(hostel_DtRm dtrm ) {
    this.dtrm=dtrm;
    initialize();
     ........
      .....  

Populating the set and get methods from "hostel_DtRm" class from the "LogedInMain" class

hostel_DtRm dtrm= new hostel_DtRm();

dtrm.setguests(guests.getText());
dtrm.setstartdate(((JTextField)checkin.getDateEditor().getUiComponent()).getText());
dtrm.setenddate(((JTextField)checkout.getDateEditor().getUiComponent()).getText());

"TEST" is the class where I want to manipulate the acquired data.

public class TEST {
private hostel_DtRm dtrm;

public TEST( hostel_DtRm dtrm) {


    this.dtrm=dtrm;
     initialize();

}

private void initialize() {

JLabel guest = new JLabel(dtrm.getguests());
guest.setForeground(Color.DARK_GRAY);
guest.setBounds(41, 141, 86, 27);
LogedInmain.add(guest);

Instead of acquiring the guest number I get a beautiful "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"

What I did wrong?

Klayd Pro
  • 1
  • 1
  • 2
  • 7
  • 1
    Please look into Java naming conventions. You are violating them all over the place. – GhostCat Apr 19 '18 at 17:15
  • And even if this wouldn't be such a basic problem - we would need a real [mcve] in order to help you. You are only giving us parts of your code, and guess what: that exception stack trace points to a specific line in your code. Long story short: even when this would be a problem where people normally spend time on debugging with you (with NPEs that wont happen) ... we couldn't. Because half of the relevant information is missing. – GhostCat Apr 19 '18 at 17:17

0 Answers0