How to fix error: The method... in the type... is not applicable for the arguments( )

Hello, I am new to Processing and am trying to create objects for the first time.

I keep getting the error message: The method drawSynapse(float, float) in the type sketch_2D_Circles.Synapse is not applicable for the arguments( )

What am I doing wrong? I couldn't find any reason why...

Synapse syn; //declaring the object syn

void setup(){
  size(500,500);
  background(0);
  smooth();
  ellipseMode(RADIUS);
  syn = new Synapse(10.0, 15.0); // making a new object called syn and passing in the initial variables
}

void draw(){
  syn.drawSynapse();
}

class Synapse { //the class is the blueprint for each Synapse object
  float x;
  float y;
  //float angle;

  Synapse(float tempX, float tempY){ //only add fields here that you want changed for each new synapse. 
    x = tempX;
    y = tempY;
    //angle = tempAngle;
  }

  void drawSynapse(float x, float y){
    ellipse(x, y, 10, 10); 
  }  
}
Tagged:

Answers

  • edited March 2014

    Don't you see that your drawSynapse() demands 2 passing arguments? /:)
    Either call it w/ those values or remove the demanding parameters from the method itself! ~:>

  • Thanks for the reply!

    I'm sorry but could you or someone else please clarify what you mean by "demands 2 passing arguments" ?

    Which line exactly?

  • I've deleted some code I commented out in the previous post. This is more clear:

    Synapse syn; //declaring the object syn
    
    void setup(){
      size(500,500);
      background(0);
      smooth();
      ellipseMode(RADIUS);
      syn = new Synapse(10.0, 15.0); // making a new object called syn and passing in the initial variables
    }
    
    void draw(){
      syn.drawSynapse();
    }
    
    class Synapse { //the class is the blueprint for each Synapse object
      float x;
      float y;
    
      Synapse(float tempX, float tempY){ //only add fields here that you want changed for each new synapse. 
        x = tempX;
        y = tempY;
      }
    
      void drawSynapse(float x, float y){
        ellipse(x, y, 10, 10); 
      }  
    }
    
  • edited March 2014

    Ah, do you mean by lines 11-13 write this instead:

    void draw(){
      syn.drawSynapse(10.0, 25.0);
    }
    

    Where I actually give passing arguments?

    It's weird because I was simply copying the syntax of the example given in the "Getting Started with Processing" book where they do not specify passing arguments.

  • Yes, that causes the error. But the real solution is probably the other way around.

    void drawSynapse(){
        ellipse(x, y, 10, 10);
      }  
    

    at line 24. Your Synapse class has two variables, x and y. So it seems logical you use those as the position for the ellipse. But if you did void drawSynapse(float x, float y) instead, it uses the x and y you gave in in line 12, which would not be the position you created the Synaps in.

  • _vk_vk
    Answer ✓

    Arguments are the "things" you "pass" into a function.

    in a function like

    void drawE (int x, int y){
         ellipse(x, y, 20 , 20);
    }
    

    x and y are the arguments or parameters.

    When you call it you should use the proper type and numbers of arguments, like:

    drawE(20, 30);

    this would not work

    drawE("string", 'c');

    neither this

    drawE(10);

Sign In or Register to comment.