public class welcomepage extends javax.swing.JFrame {
backendcode bec;
String username;
public welcomepage() {
initComponents();
username=null;
backendcode bec= new backendcode("dummy");
System.out.println("bec created "+ bec);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("bec created "+ bec);
bec.back_login_credentials(username);
}
/*
and other private methods(not mentioned here) which also needs to access bec object
*/
}
public class backendcode {
public backendcode(String dummy) {
//some code
}
public void back_login_credentials(String username, String password) {
//some code
}
}
i have declared bec(backendcode object so that it is visible to entire class)as member data inside welcomepage class and initialised in its construcor
but it gets created inside that construcor with some intialisations but bec object’s value inside jButton1ActionPerformed method will be null. why is it.. what is the solution to get that intialised object instance??
The global
becvariable is never initialized. You create a newbecvariable in the scope of your constructor.Try the following: