找不到班级错误,不知道出了什么问题

时间:2013-10-29 10:25:20

标签: java processing

今天我偶然发现了所有错误中最致命的错误。处理没有看到我的班级...我不知道为什么它没有,因为我很擅长这个。

这是我的主要课程:

Player thePlayer = new Player();
Guard theGuard = new Guard();
SpeedPWRUP speedPowerUp = new SpeedPWRUP();
Keyboard theKeyboard = new Keyboard();

void setup() {
  size(1000, 500);
  theGuard.init();
  thePlayer.init();
  speedPowerUp.init();
}

void updateGame() {
  theGuard.update();
  thePlayer.update();
  speedPowerUp.update();
}

void drawGame() {
  thePlayer.draw();
  theGuard.draw();
  speedPowerUp.draw();
  fill(color(0, 0, 0));
  text(("Score:"), 10, 20);
}

void draw() {
  background(255);
  fill (0, 0, 0);
  rect(-10, 401, 1100, 100);
  noFill();

  updateGame();
  drawGame();
  Keyboard();
}

这是我的玩家类:

  class Player {

  public float playerX, playerY;
  float vx, vy;
  int fillColor;
  float diameterPlayer;
  float jumpTime;
  float jumpHeight;
  boolean isJumping;
  float collisionGuard;
  boolean speedUpActive;
  boolean facingRight;

void init() {
  diameterPlayer = 40;
  fillColor = color(0, 0, 0);
  jumpTime = 200;
  jumpHeight = 100;
  isJumping = false;
  collisionGuard = 80;
  speedUpActive = false;
  facingRight = false;

  playerX = 100;
  playerY = 400-diameterPlayer;

  vx = 0;
  vy = 0;
}

void update() {

  if(theKeyboard.holdingUp == true && isOnGround == true) {
    vx = 5;
    isOnGround = false;
  }

  if(theKeyboard.holdingDown == true) {
    diameterPlayer = 40;
  }

  if(theKeyboard.holdingLeft == true) {
    vx = -2;
  }

  if(theKeyboard.holdingRight == true) {
    vx = 2;
  }

  if (playerY < (400-diameterPlayer/2)) {
  vy = vy + 2.5;
  }

  if (playerY < (80-diameterPlayer/2)) {
  vy = 2.5;
  }

  if (playerX < (0+diameterPlayer/2)) {
  vx = 0.1;
  }

  if(vx>0) {
    facingRight = true;
  } else if(vx<0) { facingRight = false;
  } else facingRight = false;

  playerX += vx;
  playerY += vy;

}

void draw() {
  fill(fillColor);
  ellipse(playerX, playerY, diameterPlayer, diameterPlayer);
  noFill();
}
}

错误发生在我的主类的第一行(“Player thePlayer = new Player();”),错误显示“无法找到类或类型”播放器“”。有人请帮助我:(提前致谢!

4 个答案:

答案 0 :(得分:0)

如果Player类与Main类不在同一个包中。然后你需要在Main类中导入Player类,如下所示。

import XXX.Player;

//你的主类代码就在这里。

答案 1 :(得分:0)

将您的Player类放在代码中的主类之上。然后它会工作。

答案 2 :(得分:0)

将您的Player类与Main类放在同一目录中 否则使用完整的包名称导入Player类存储....或者可能存在小的或资本差异.....

答案 3 :(得分:0)

您是否已将类Player导入到与Main类相同的包中?

让玩家公开并重试:

  

public class Player {...}