[Resolved] G4P - for loop to create buttons in a window - EXCEPTION IN EVENT HANDLER -
in
Contributed Library Questions
•
2 years ago
hi,
In the main window, i have a checkbox controlling the opening of an other window where i want to put as much buttons as the value of a parameter. I decided to create a for loop to do so.
see code below :
but i'v got this error :
if someone can told me why Or help me to found an other way to do the same think, i will appreciate :)
In the main window, i have a checkbox controlling the opening of an other window where i want to put as much buttons as the value of a parameter. I decided to create a for loop to do so.
see code below :
- import guicomponents.*;
- GButton[] modules;
- GWindow window;
- GCheckbox checkbox;
- int imax = 4;
- color colorBg = color(150);
- void setup(){
- size(200,200);
- background(colorBg);
- checkbox= new GCheckbox(this,"check", 10,10,10);
- }
- void draw(){
- }
- void createWindow(){
- window=new GWindow(this, "test", 10,10,100,100,false,JAVA2D);
- window.setBackground(colorBg);
- for(int i=0; i<imax; i++){
- modules[i]=new GButton(this, "buttonTest "+nf(i,2),10,10+i*12,10,10);
- window.add(modules[i]);
- }
- }
- void handleCheckboxEvents(GCheckbox checkbox) {
- createWindow();
- }
but i'v got this error :
############# EXCEPTION IN EVENT HANDLER #############
An error occured during execution of the eventhandler:
CLASS: sketch_aug21c METHOD: handleCheckboxEvents
Caused by java.lang.NullPointerException
sketch_aug21c.createWindow(sketch_aug21c.java:51)
########################################################
if someone can told me why Or help me to found an other way to do the same think, i will appreciate :)
1