G4P window returning null

Hello, hope you doing all well , so i was adding a loading window to wait for configuration, first of all, this screen is trigerred upon a button click in another window, here s the code of the loading window :

public void Lancer_mesures_click(GButton source, GEvent event) { 
  if (event == GEvent.CLICKED) {
      if (parameters_window != null && parameters_window.isVisible()) {
      parameters_window.setVisible(false); // Set the main window's visibility to false
      if (loading_window!=null) {
        loading_window.setVisible(true);
      } else {
      GWindow loading_window = GWindow.getWindow(this, "Chargement.....", 0, 0, 900, 600, JAVA2D);
      loading_window.noLoop();
      loading_window.setActionOnClose(G4P.CLOSE_WINDOW);
      loading_window.addDrawHandler(this, "loading_window_draw");
     Ok_config = new GButton(loading_window, 430, 350, 130, 30);
     Ok_config.setText("OK");
     Ok_config.addEventHandler(this, "Ok_config_click");
     Ok_config.setVisible(false);
     config_label = new GLabel(loading_window, 430, 300, 150, 20);
     config_label.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
     config_label.setText("Configuration en cours.....");
     config_label.setOpaque(false);
     loading_window.loop();
      }
    }
  
  }
}

then of course once the configuration is done, the OK button visibility change from false to true and once clicked it s should set to loading window visibility to false and load a new window like this :

void Ok_config_click(GButton source, GEvent event){
  if(event==GEvent.CLICKED) {

    if(loading_window==null) {
      println("window is null ");
    }
    if(loading_window != null && loading_window.isVisible()) {
       loading_window.setVisible(false);
        if(Suivi_mesures!=null) {
    Suivi_mesures.setVisible(true);
  }else {
    Suivi_mesures = GWindow.getWindow(this, "Suivi des mesures", 0, 0, 1000, 600, JAVA2D);
  Suivi_mesures.noLoop();
  Suivi_mesures.setActionOnClose(G4P.CLOSE_WINDOW);
  Suivi_mesures.addDrawHandler(this, "Suivi_mesures_draw");
  enregistrer_mesures = new GButton(Suivi_mesures, 899, 552, 80, 30);
  enregistrer_mesures.setText("Enregistrer ");
  enregistrer_mesures.addEventHandler(this, "enregistrer_mesures_click");
  plot = new GPlot(Suivi_mesures); 
  plot.setPos(0, 86);
  plot.setDim(900, 350);
  plot.setTitleText("Suivi des mesures");
  plot.getXAxis().setAxisLabelText("Temps (s)");
  plot.getYAxis().setAxisLabelText("RSSI (dBm)");
  plot.activateZooming();
  plot.activatePanning();
  Filtres_label = new GLabel(Suivi_mesures, 459, 8, 80, 20);
  Filtres_label.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  Filtres_label.setText("Filtres");
  Filtres_label.setOpaque(false);
  Technologie_filtre = new GDropList(Suivi_mesures, 148, 50, 100, 80, 3, 10);
  Technologie_filtre.setItems(loadStrings("list_368846"), 0);
  Technologie_filtre.addEventHandler(this, "Technologie_filtre_click");
  metrique_filtre = new GDropList(Suivi_mesures, 389, 50, 100, 80, 3, 10);
  metrique_filtre.setItems(loadStrings("list_795386"), 0);
  metrique_filtre.addEventHandler(this, "metrique_filtre_click");
  technologies_label = new GLabel(Suivi_mesures, 36, 50, 80, 20);
  technologies_label.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  technologies_label.setText("Technologie");
  technologies_label.setOpaque(false);
  metrique_label = new GLabel(Suivi_mesures, 288, 50, 80, 20);
  metrique_label.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  metrique_label.setText("Metrique");
  metrique_label.setOpaque(false);
  Gateway_Label = new GLabel(Suivi_mesures, 530, 50, 80, 20);
  Gateway_Label.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  Gateway_Label.setText("Gateway");
  Gateway_Label.setOpaque(false);
  Gateway_List = new GDropList(Suivi_mesures, 641, 50, 90, 80, 3, 10);
  Gateway_List.setItems(loadStrings("list_848799"), 0);
  Gateway_List.addEventHandler(this, "Gateway_List_click");
  progression_bar_label = new GLabel(Suivi_mesures, 450, 570, 130, 20);
  progression_bar_label.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  progression_bar_label.setText("En Cours..");
  progression_bar_label.setOpaque(false);
  button_mesure = new GButton(Suivi_mesures, 26, 552, 130, 30);
  button_mesure.setText("Nouvelle mesure");
  button_mesure.addEventHandler(this, "button_mesure_click");
  button_mesure.setVisible(false);
  annuler = new GButton(Suivi_mesures, 795, 551, 80, 30);
  annuler.setText("annuler");
  annuler.addEventHandler(this, "annuler_mesures_click");
  Suivi_mesures.loop();
  }
    }
  
  }
}

however, each time i click on the button it says to me that the loading window is null !!! why is that happening although i can clearly see the window with the button ?!

In the first function posted you find the line

GWindow loading_window = GWindow.getWindow(this, "Chargement.....", 0, 0, 900, 600, JAVA2D);
      

You are creating a local variable called loading_window so the global variable of the same name remains null :grinning:

Oh, i didn’t see it, thanks !