java 该方法不适用于参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12294297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:20:00  来源:igfitidea点击:

the method is not applicable for the arguments

javaclassmethodsarguments

提问by Zeta Op

I get this error:

我收到此错误:

the method pintar() in the type t33.Psicodelia is not applicable for the arguments (int,int,int,int,int,int)

t33.Psicodelia 类型中的 pintar() 方法不适用于参数 (int,int,int,int,int,int)

How can I solve this?

我该如何解决这个问题?

I have two classes and the main tab:

我有两个类和主选项卡:

Class 1

1级

public class Logica {
  Psicodelia miPsicodelia;


  public Logica() {
  }

  public void pintar() {
    miPsicodelia.pintar(width/2, height/2, height/4, 0, 0, 1);
    miPsicodelia.kaleidouno(posX, posY, rad, ang, depth, tam1);
  }  

  public void pressed() {
    miPsicodelia.pressed();
  }
}

Class 2

2级

public class Psicodelia {
  private float anguloGrande;
  private int numBolas, contador;


  public Psicodelia() {
    stroke(255);   
    this.anguloGrande = 0.0;
    this.numBolas = 7;
  }


  public void pintar() {
    //fill((int)random(0, 255), (int)random(0, 255), (int)random(0, 255));
    fill(255, 255, 0, (int)random(20, 100));
    pintar(width/2, height/2, height/4, 0, 0, 1);
    anguloGrande += .02; //velocidad de rotacion
  }

  public void kaleidouno(float posX, float posY, float rad, float ang, int depth, float tam) { //pinteme las bolas en la pos posX, posY, reciba un float de radianes y de angulos, y por ultimo un int de profundidad
    if (depth < contador) {
      tam=(int)random(0.5, 1.5);
      float anguloPeq = TWO_PI/numBolas;
      for (int i=0; i < numBolas; i++) {
        float nuevoRad = rad/2; //distancia y tama?o de las bolas entre ellas
        float nuevoAng = ang + i*anguloPeq - anguloGrande;
        float X = cos(nuevoAng)*rad + posX;
        float Y = sin(nuevoAng)*rad + posY;
        pintar(X, Y, nuevoRad, nuevoAng, depth + 1, 1);
      }
    }
    else  if (rad < 2) { 
      ellipse(posX, posY, 2.0*tam, 2.0*tam);
    }
    else { 

      ellipse(posX, posY, rad*2.0, rad*2.0);
    }
  }

  public void pressed() {
    contador++;
    if (contador >= 3) { 

      contador--;
    }
  }



  float getPosX () {
    return posX ;
  }


  float getPosY () {
    return posY ;
  }
}


// and the main tab


Logica miLogica;

//================================================================

void setup() {
  size(800,600);
  smooth();

miLogica= new Logica();

}

//================================================================

void draw() {
  background(0);
 miLogica.pintar();

}

//================================================================

void mousePressed() {
miLogica.pressed();
}
//================================================================

回答by Christoph Schubert

You called the method

你调用了方法

Psicodelia miPsicodelia;
miPsicodelia.pintar(width/2, height/2, height/4, 0, 0, 1);

But your Psicodeliaclass only has following pintarmethod:

但是你的Psicodelia班级只有以下pintar方法:

public void pintar();

To call it the way you did you must give the method pintar()the wished parameter.

要按照您的方式调用它,您必须为该方法提供所需pintar()的参数。

For Example:

例如:

public void pintar(int a, int b, int c, int d, int e, int f){
    // do whatever you want here
}

P.S.: Do you instantiate yourmiPsicodeliaObject anywhere? If not this will get you aNullPointerException.

PS:你在miPsicodelia任何地方实例化你的对象吗?如果不是,这会给你一个NullPointerException.

回答by Christian

Well, unless I miss something, your public void pintar()method is declared with no parameters, so you can't call it with any. You'd have to declare it with your desired number and types of parameters:

好吧,除非我错过了什么,否则您的public void pintar()方法声明时没有参数,因此您不能使用任何参数调用它。您必须使用所需的参数数量和类型来声明它:

public void pintar(int para1, int para2, int para3, int para4, int para5, int para6)
{ 
   //Do something with the parameters.
}