繁体   English   中英

调用方法时出错

[英]Error when calling method

在FloodFill类中,我定义了要在setupdraw调用的resolution方法。 但是当我添加resolution(String[] args); 这么说,我有一个错误,说我错过了右括号。

这是完整的代码:

static int[][] matrix={
    {1,1,1,1,1,1,1,1,1,1,1},
    {1,2,2,2,2,2,2,2,2,2,1},
    {1,2,3,3,3,3,3,3,3,2,1},
    {1,2,3,4,4,4,4,4,3,2,1},
    {1,2,3,4,1,1,1,4,3,2,1},
    {1,2,3,4,1,1,1,4,3,2,1},
    {1,2,3,4,1,1,1,4,3,2,1},
    {1,2,3,4,4,4,4,4,3,2,1},
    {1,2,3,3,3,3,3,3,3,2,1},
    {1,2,2,2,2,2,2,2,2,2,1},
    {1,1,1,1,1,1,1,1,1,1,1},
  };

void setup() {
  size(1000, 600);
  noCursor();
  noStroke();
  fill(0);

  // periodic updates
  if (!callback) {
    frameRate(60); //<>//
    loop();
  } else noLoop(); // or callback updates 
  //int[][] array = new int[10][10];
  //System.out.println(Arrays.deepToString(array));
  tuioClient  = new TuioProcessing(this);
  System.out.println(Arrays.deepToString(grid));

resolution(String[] args) ;

}


void draw() {

  // This part detects the fiducial markers 
  float obj_size = object_size*scale_factor; 
  float cur_size = cursor_size*scale_factor; 

  ArrayList<TuioObject> tuioObjectList = tuioClient.getTuioObjectList();
  for (int i=0; i<tuioObjectList.size (); i++) {
    TuioObject tobj= tuioObjectList.get(i);
    stroke(0);
    fill(0, 0, 0);
    pushMatrix();
    translate(tobj.getScreenX(width), tobj.getScreenY(height));
    rotate(tobj.getAngle());
    rect(-80, -40, 80, 40);
    popMatrix();
    fill(255);
    x = round(10*tobj.getX ());
    y = round(10*tobj.getY ());
    iD = tobj.getSymbolID();
    int taille = fiducialsList.length;
    for (int o = 0; o<taille; o++) {
      if (iD == o) { 
        myType = fiducialsList [o];
      }
    } 
    //System.out.println(myType);
    activList.add(new Fiducial (x, y, iD, myType));
    fiducialCoordinates ();
    grid [x][y] = 1 ;

    circuitState ();
    for (int p = 0; p < 10; p++) {
      for (int r = 0; r < 10; r++) {
        System.out.print(grid[p][r] + " ");
      }
      System.out.print("\n");
    }
    System.out.print("\n");
    // activList.removeAll(activList);
  }
  for (int[] row : grid)
    Arrays.fill(row, 0);
}

void fiducialCoordinates () {
  System.out.println(activList);
}


public static class FloodFill {

  public static void resolution(String[] args) {
 // Do stuff
  }
public static void solve(int[][] matrix, int x, int y, int fillValue) {
// Do stuff
}

当我调用其他方法(例如fiducialCoordinates (); )时,它可以正常工作。 由于此方法是在特定类中定义的,因此还有另一种方法可以调用此方法吗?

这是处理中使用的Java。 谢谢你的帮助

调用时不需要String[]

FloodFill.resolution(args) ;

应该足够了

调用方法时,请勿指定参数的类型:

resolution(args);

应该可以工作(除了args定义的地方-您需要将这些参数从main()方法传递给setup() main()方法)。

此外, resolution是在单独的类中定义的,因此您必须这样称呼它:

FloodFill.resolution(args);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM