What does it mean : Cannot invoke disableStyle() on the primitive int ? in this script?

edited January 2014 in Questions about Code

Hi, here you are my code... at Y.disableStyle(); (line 253) it says Cannot invoke disableStyle() on the primitive int , what does it mean? Why for R.disableStyle(); nothing goes wrong? Please comment where (line) i'm falling and how-where to solve... becouse i'm not to good understanding english answers and i don't want you to lose time... Thanks!

import java.awt.Frame;
import java.awt.BorderLayout;
import controlP5.*;

private ControlP5 cp5;

Accordion accordion;

ControlFrame cf;

PShape R;
PShape Y;

int def;

void setup() {
  size(400, 400);
  cp5 = new ControlP5(this);

  // by calling function addControlFrame() a
  // new frame is created and an instance of class
  // ControlFrame is instanziated.
  cf = addControlFrame("extra", 200,700);

  // add Controllers to the 'extra' Frame inside 
  // the ControlFrame class setup() method below.


}

void draw() {
  background(def);
}

ControlFrame addControlFrame(String theName, int theWidth, int theHeight) {
  Frame f = new Frame(theName);
  ControlFrame p = new ControlFrame(this, theWidth, theHeight);
  f.add(p);
  p.init();
  f.setTitle(theName);
  f.setSize(p.w, p.h);
  f.setLocation(100, 100);
  f.setResizable(false);
  f.setVisible(true);
  return p;
}


// the ControlFrame class extends PApplet, so we 
// are creating a new processing applet inside a
// new frame with a controlP5 object loaded
public class ControlFrame extends PApplet {

  int w, h;

  int abc = 100;

  public void setup() {
    size(w, h);
    frameRate(25);
    cp5 = new ControlP5(this);
    // group number 1, contains 2 bangs
  Group g1 = cp5.addGroup("colore")
                .setBackgroundColor(color(0, 64))
                .setBackgroundHeight(100)
                ;

  cp5.addSlider("HueR")
     .setPosition(10,20)
     .setSize(100,20)
     .setRange(0,360)
     .setValue(100)
     .moveTo(g1)
     ;

  cp5.addSlider("HueY")
     .setPosition(10,50)
     .setSize(100,20)
     .setRange(0,360)
     .setValue(200)
     .moveTo(g1)
     ;



  // group number 2, contains a radiobutton
  Group g2 = cp5.addGroup("tono")
                .setBackgroundColor(color(0, 64))
                .setBackgroundHeight(150)
                ;

  cp5.addSlider("tonoR")
     .setPosition(10,20)
     .setSize(100,20)
     .setRange(0,100)
     .setValue(100)
     .moveTo(g2)
     ;

  cp5.addSlider("tonoY")
     .setPosition(10,80)
     .setSize(100,20)
     .setRange(0,100)
     .setValue(100)
     .moveTo(g2)
     ;

   cp5.addSlider("saturazioneR")
     .setPosition(10,50)
     .setSize(100,20)
     .setRange(0,100)
     .setValue(100)
     .moveTo(g2)
     ;

  cp5.addSlider("saturazioneY")
     .setPosition(10,110)
     .setSize(100,20)
     .setRange(0,100)
     .setValue(100)
     .moveTo(g2)
     ;

  // group number 3, contains a bang and a slider
  Group g3 = cp5.addGroup("dimensione")
                .setBackgroundColor(color(0, 64))
                .setBackgroundHeight(100)
                ;


  cp5.addSlider("dimensioneR")
     .setPosition(10,20)
     .setSize(100,20)
     .setRange(100,300)
     .setValue(100)
     .moveTo(g3)
     ;

  cp5.addSlider("dimensioneY")
     .setPosition(10,50)
     .setSize(100,20)
     .setRange(100,300)
     .setValue(100)
     .moveTo(g3)
     ;

  // group number 4, contains a bang and a slider
  Group g4 = cp5.addGroup("posizione")
                .setBackgroundColor(color(0, 64))
                .setBackgroundHeight(150)
                ;


  cp5.addSlider("posizioRx")
     .setPosition(10,20)
     .setSize(100,20)
     .setRange(0,400)
     .setValue(200)
     .moveTo(g4)
     ;

  cp5.addSlider("posizioRy")
     .setPosition(10,50)
     .setSize(100,20)
     .setRange(0,400)
     .setValue(200)
     .moveTo(g4)
     ;

  cp5.addSlider("posizioYx")
     .setPosition(10,80)
     .setSize(100,20)
     .setRange(0,600)
     .setValue(100)
     .moveTo(g4)
     ;

  cp5.addSlider("posizioYy")
     .setPosition(10,110)
     .setSize(100,20)
     .setRange(0,600)
     .setValue(100)
     .moveTo(g4)
     ;


  // group number 5, contains a bang and a slider
  Group g5 = cp5.addGroup("distanza fruitore cm")
                .setBackgroundColor(color(0, 64))
                .setBackgroundHeight(50)
                ;


  cp5.addSlider("distanza cm")
     .setPosition(10,20)
     .setSize(100,20)
     .setRange(0,1000)
     .setValue(200)
     .moveTo(g5)
     ;

  // create a new accordion
  // add g1, g2, and g3 to the accordion.
  accordion = cp5.addAccordion("acc")
                 .setPosition(0,0)
                 .setWidth(200)
                 .addItem(g1)
                 .addItem(g2)
                 .addItem(g3)
                 .addItem(g4)
                 .addItem(g5)
                 ;

  cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.open(0,1,2);}}, 'o');
  cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.close(0,1,2);}}, 'c');
  cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setWidth(300);}}, '1');
  cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setPosition(0,0);accordion.setItemHeight(190);}}, '2'); 
  cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setCollapseMode(ControlP5.ALL);}}, '3');
  cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setCollapseMode(ControlP5.SINGLE);}}, '4');
  cp5.mapKeyFor(new ControlKey() {public void keyEvent() {cp5.remove("myGroup1");}}, '0');

  accordion.open(0,1,2);

  // use Accordion.MULTI to allow multiple group 
  // to be open at a time.
  accordion.setCollapseMode(Accordion.MULTI);

  // when in SINGLE mode, only 1 accordion  
  // group can be open at a time.  
  // accordion.setCollapseMode(Accordion.SINGLE);
  }

  public void draw() {
      background(abc);
  R.disableStyle();  // Ignore the colors in the SVG
  //fill(45, 45, Brightness);    // Set the SVG fill to...
  //stroke(255);          // Set the SVG fill to...

  int hueR = (int) cp5.getController("HueR").getValue();
  int satR = (int) cp5.getController("saturazioneR").getValue();  

  int tonR = (int) cp5.getController("tonoR").getValue();
  int d1 = (int) cp5.getController("dimensioneR").getValue();

  int posRx = (int) cp5.getController("posizioRx").getValue();
  int posRy = (int) cp5.getController("posizioRy").getValue();



  shape(R, posRx, posRy, d1, d1);
  fill(hueR, satR, 100-tonR);

  Y.disableStyle();  // Ignore the colors in the SVG
  //fill(45, 45, Brightness);    // Set the SVG fill to...
  //stroke(255);          // Set the SVG fill to...


  int hueY = (int) cp5.getController("HueY").getValue();
  int satY = (int) cp5.getController("saturazioneY").getValue();

  int tonY = (int) cp5.getController("tonoY").getValue();

  int d2 = (int) cp5.getController("dimensioneY").getValue();

  int posYx = (int) cp5.getController("posizioYx").getValue();
  int posYy = (int) cp5.getController("posizioYy").getValue();

  shape(Y, posYx, posYy, d2, d2);
  fill(hueY, satY,100- tonY);


  int dist = (int) cp5.getController("distanza cm").getValue();
  if (keyPressed) {
    if (key == 'b' || key == 'B') {
      ellipse(mouseX, mouseY, dist, dist);
    }
   }

  }

  private ControlFrame() {
  }

  public ControlFrame(Object theParent, int theWidth, int theHeight) {
    parent = theParent;
    w = theWidth;
    h = theHeight;
  }


  public ControlP5 control() {
    return cp5;
  }


  ControlP5 cp5;

  Object parent;


}

Answers

  • That sure is a lot of code to ask us to debug for you. I suggest you try to boil it down to as few lines as possible- start with a blank sketch and only add enough code so that it shows the same error as your full sketch, and we'll go from there.

  • Answer ✓

    Y is variable name used by Processing: static public final int Y = 1;

    See: https://github.com/processing/processing/blob/master/core/src/processing/core/PConstants.java#L43

    The solution to your problem is to choose another name instead of Y.

  • I don't think that's correct. This works fine for me:

     String Y = "testing";
     String y = "testing again";
    
    void setup(){
     println(Y);
     println(y); 
    }
    
  • Thanks to both Kevin and amnon, now i'll fix and in the future i'll post only interesting portions!

    :)>-

  • :( Now i've used A , B but at A.disableStyle(); i get NullPointerException... Sorry Kevin but don't know where the error is and so is hard to choose what portion of script i've to show... i've tryed to do some order and comments...

    thanks, Filippo

    import java.awt.Frame;
    import java.awt.BorderLayout;
    import controlP5.*;
    
    private ControlP5 cp5;
    
    Accordion accordion;
    
    ControlFrame cf;
    
    
    
    PShape A;
    PShape B;
    
    int def;
    
    
    
    void setup() {
      size(400, 600);
      cp5 = new ControlP5(this);
    
      cf = addControlFrame("extra", 200,700);
    
       colorMode(HSB, 360, 100, 100);
      noStroke();
      A = loadShape("Rprocessing.svg");
      B = loadShape("Yprocessing.svg");
      smooth();
    
    }
    
    
    
    
    void draw() {
    
      background(def);
    
    }
    
    //ControlP5 lib portion about new frame
    
    ControlFrame addControlFrame(String theName, int theWidth, int theHeight) {
      Frame f = new Frame(theName);
      ControlFrame p = new ControlFrame(this, theWidth, theHeight);
      f.add(p);
      p.init();
      f.setTitle(theName);
      f.setSize(p.w, p.h);
      f.setLocation(100, 100);
      f.setResizable(false);
      f.setVisible(true);
      return p;
    }
    
    
    public class ControlFrame extends PApplet {
    
      int w, h;
    
      int abc = 100;
    
      public void setup() {
        size(w, h);
        frameRate(25);
        cp5 = new ControlP5(this);
    
    //creating groups for the ControlP5 accordin
    
      //group1
      Group g1 = cp5.addGroup("colore")
                    .setBackgroundColor(color(0, 64))
                    .setBackgroundHeight(100)
                    ;
    
      cp5.addSlider("HueA")
         .setPosition(10,20)
         .setSize(100,20)
         .setRange(0,360)
         .setValue(100)
         .moveTo(g1)
         ;
    
      cp5.addSlider("HueB")
         .setPosition(10,50)
         .setSize(100,20)
         .setRange(0,360)
         .setValue(200)
         .moveTo(g1)
         ;
    
    
    
      // group number 2
      Group g2 = cp5.addGroup("tono")
                    .setBackgroundColor(color(0, 64))
                    .setBackgroundHeight(150)
                    ;
    
      cp5.addSlider("tonoA")
         .setPosition(10,20)
         .setSize(100,20)
         .setRange(0,100)
         .setValue(100)
         .moveTo(g2)
         ;
    
      cp5.addSlider("tonoB")
         .setPosition(10,80)
         .setSize(100,20)
         .setRange(0,100)
         .setValue(100)
         .moveTo(g2)
         ;
    
       cp5.addSlider("saturazioneA")
         .setPosition(10,50)
         .setSize(100,20)
         .setRange(0,100)
         .setValue(100)
         .moveTo(g2)
         ;
    
      cp5.addSlider("saturazioneB")
         .setPosition(10,110)
         .setSize(100,20)
         .setRange(0,100)
         .setValue(100)
         .moveTo(g2)
         ;
    
      // group number 3
      Group g3 = cp5.addGroup("dimensione")
                    .setBackgroundColor(color(0, 64))
                    .setBackgroundHeight(100)
                    ;
    
    
      cp5.addSlider("dimensioneA")
         .setPosition(10,20)
         .setSize(100,20)
         .setRange(100,300)
         .setValue(100)
         .moveTo(g3)
         ;
    
      cp5.addSlider("dimensioneB")
         .setPosition(10,50)
         .setSize(100,20)
         .setRange(100,300)
         .setValue(100)
         .moveTo(g3)
         ;
    
      // group number 4
      Group g4 = cp5.addGroup("posizione")
                    .setBackgroundColor(color(0, 64))
                    .setBackgroundHeight(150)
                    ;
    
    
      cp5.addSlider("posizioAx")
         .setPosition(10,20)
         .setSize(100,20)
         .setRange(0,400)
         .setValue(200)
         .moveTo(g4)
         ;
    
      cp5.addSlider("posizioAy")
         .setPosition(10,50)
         .setSize(100,20)
         .setRange(0,400)
         .setValue(200)
         .moveTo(g4)
         ;
    
      cp5.addSlider("posizioBx")
         .setPosition(10,80)
         .setSize(100,20)
         .setRange(0,600)
         .setValue(100)
         .moveTo(g4)
         ;
    
      cp5.addSlider("posizioBy")
         .setPosition(10,110)
         .setSize(100,20)
         .setRange(0,600)
         .setValue(100)
         .moveTo(g4)
         ;
    
    
      // group number 5
      Group g5 = cp5.addGroup("distanza fruitore cm")
                    .setBackgroundColor(color(0, 64))
                    .setBackgroundHeight(50)
                    ;
    
    
      cp5.addSlider("distanza cm")
         .setPosition(10,20)
         .setSize(100,20)
         .setRange(0,1000)
         .setValue(200)
         .moveTo(g5)
         ;
    
      // create a new accordion
      // add g1, g2, and g3 to the accordion.
      accordion = cp5.addAccordion("acc")
                     .setPosition(0,0)
                     .setWidth(200)
                     .addItem(g1)
                     .addItem(g2)
                     .addItem(g3)
                     .addItem(g4)
                     .addItem(g5)
                     ;
    
      cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.open(0,1,2);}}, 'o');
      cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.close(0,1,2);}}, 'c');
      cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setWidth(300);}}, '1');
      cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setPosition(0,0);accordion.setItemHeight(190);}}, '2'); 
      cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setCollapseMode(ControlP5.ALL);}}, '3');
      cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setCollapseMode(ControlP5.SINGLE);}}, '4');
      cp5.mapKeyFor(new ControlKey() {public void keyEvent() {cp5.remove("myGroup1");}}, '0');
    
      accordion.open(0,1,2);
    
      accordion.setCollapseMode(Accordion.MULTI);
    
      }
    
      public void draw() {
          background(abc);
    
      A.disableStyle();     
    
      int hueA = (int) cp5.getController("HueA").getValue();
      int satA = (int) cp5.getController("saturazioneA").getValue();  
      int tonA = (int) cp5.getController("tonoA").getValue();
      int d1 = (int) cp5.getController("dimensioneA").getValue();
      int posAx = (int) cp5.getController("posizioAx").getValue();
      int posAy = (int) cp5.getController("posizioAy").getValue();
    
      shape(A, posAx, posAy, d1, d1);
      fill(hueA, satA, 100-tonA);
    
    
    
      B.disableStyle();
    
      int hueB = (int) cp5.getController("HueB").getValue();
      int satB = (int) cp5.getController("saturazioneB").getValue();
      int tonB = (int) cp5.getController("tonoB").getValue();
      int d2 = (int) cp5.getController("dimensioneB").getValue();
      int posBx = (int) cp5.getController("posizioBx").getValue();
      int posBy = (int) cp5.getController("posizioBy").getValue();
    
      shape(B, posBx, posBy, d2, d2);
      fill(hueB, satB,100- tonB);
    
    
    
    
      //a keypressed collegated to a slidervalue
      int dist = (int) cp5.getController("distanza cm").getValue();
      if (keyPressed) {
        if (key == 'b' || key == 'B') {
          ellipse(mouseX, mouseY, dist, dist);
        }
       }
    
      }
    
      private ControlFrame() {
      }
    
      public ControlFrame(Object theParent, int theWidth, int theHeight) {
        parent = theParent;
        w = theWidth;
        h = theHeight;
      }
    
    
      public ControlP5 control() {
        return cp5;
      }
    
    
      ControlP5 cp5;
    
      Object parent;
    
    
    }
    
  • If you're getting a NullPointException, it should highlight the exact line that's throwing the NPE.

    But just looking at it, you're calling addControlFrame() before you initialize A and B. Do you use the values of A and B inside addControlFrame()?

  • edited January 2014

    it call the NPE (wow new slang!) at line 241. If i understand you question: I'm launching a new frame with a lot of sliders wich permit to change A and B values...

    so i have to put

           A = loadShape("Rprocessing.svg");
           B = loadShape("Yprocessing.svg");
    

    before to

    cf = addControlFrame("extra", 200,700);

    in the

    void setup()

    ?

  • i solve this problem but now other problems are accuring and so i think i've to change discussion. thank you so much everybody!

    ^:)^

  • edited January 2014

    @KevinWorkman

    How is it not correct? I show via link that there is in fact an int variable Y in Processing's PConstants. The problematic code does not contain any ints named Y, yet the error message states that disableStyle() cannot be invoked on the primitive int, so apparantly the method is called on Processing's int Y instead of the PShape variable named Y. Most importantly, renaming the PShape variable does in fact solve the problem.

    Yes, you can overwrite Processing constants, variables and methods. But doing so may result in (hard to debug) conflicts later on. My advice would be to never use names that will overwrite Processing defaults.

    And your code snippet may "work fine", but by overwriting Y it also changes both it's type and it's value inside PApplet. Copy paste and run this and you will see:

    println(Y);
    String Y = "testing";
    println(Y);
    
  • I didn't mean that the code you were showing was incorrect, I meant that it wasn't the cause of OP's error.

    I can agree with you that naming things the same as Processing variables is a bad idea, but in this case it wasn't the root cause of the error.

    I would bet that the code the OP posted was in fact not the code he was actually running, as his code did not originally throw the exception he said he was getting.

  • Hey guys now everything is running well! Both of you gives me good advices!

    best, Filippo

Sign In or Register to comment.