gpt4 book ai didi

java - 如何消除此消息错误 : Main method not found in class

转载 作者:行者123 更新时间:2023-12-01 12:22:38 25 4
gpt4 key购买 nike

我最近一直在开发这个 Java 游戏。我试图用音频剪辑添加音乐,但它不起作用,所以我取出了主文件中的代码并删除了主文件,因为我不再需要它了。所有代码与我实现音乐之前相同,但现在弹出此消息并且不允许我运行我的游戏:

Error: Main method not found in class com.illuminationsco.GoNerdGo.Entities.Obstacles, please define the main method as: public static void main(String[] args)

当我尝试放回主程序时,它根本不运行!

如果有人能帮助我那就太好了!

这是我的代码:

Bully bully = new Bully();
Nerd nerd = new Nerd();

static BufferedImage[] sprites;

public static float x, y, velX = 5.5f, velY = 5.5f;
public static int whatObstacle = 5;

public static int basketBall = 6;
public static int lava = 2;
public static int trash = 1;

public static boolean trashOpen = false;

public Rectangle getBounds() {
return null;
}

public Obstacles() {
int width = 100;
int height = 100;
int columns = 2;
int rows = 2;

BufferedImage spriteSheet = null;
try {
spriteSheet = ImageIO.read(new File(
"res/Images/ObstacleSpriteSheet.png"));
} catch (IOException e) {
e.printStackTrace();
}
sprites = new BufferedImage[rows * columns];

for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
sprites[(i * columns) + j] = spriteSheet.getSubimage(i * width,
j * height, width, height);
}
}
}

public void tick() {
if (whatObstacle >= basketBall && Game.gos == null) {
x += velX;
y += velY;
}

if (x <= 0 || x >= 800 - 35) {
velX *= -1;
}
if (y <= 425 || y >= 600 - 35) {
velY *= -1;
}
}

public void render(Graphics g) {
if (whatObstacle >= basketBall) {

// Displaying basketball

g.drawImage(sprites[3], (int) x, (int) y, null);

Rectangle basketballRect = new Rectangle((int) x, (int) y, 35, 35);

if (nerd.getFeetBounds().intersects(basketballRect)) {
Game.setOverGameState(Game.GameOverlayState.BullyWins);
}
if (bully.getFeetBounds().intersects(basketballRect)) {
Game.setOverGameState(Game.GameOverlayState.NerdWins);
}

// Displaying lava pool
} else if (whatObstacle >= lava) {

g.drawImage(sprites[2], (int) x, (int) y, null);

Rectangle lavaRect = new Rectangle((int) x + 5, (int) y + 7, 80, 19);

if (nerd.getFeetBounds().intersects(lavaRect)) {
Game.setOverGameState(Game.GameOverlayState.BullyWins);
}
if (bully.getFeetBounds().intersects(lavaRect)) {
Game.setOverGameState(Game.GameOverlayState.NerdWins);
}

// Displaying trash can

} else if (whatObstacle == trash) {

if (trashOpen) {
g.drawImage(sprites[1], (int) x, (int) y, null);
} else {
g.drawImage(sprites[0], (int) x, (int) y, null);
}

Rectangle trashRect = new Rectangle((int) x, (int) y, 60, 97);

if (bully.getBounds().intersects(trashRect)) {
Game.setOverGameState(Game.GameOverlayState.BullyWins);
Obstacles.trashOpen = true;
}
}
}

最佳答案

在你的类中插入一个主方法 - public static void main(String[] args)!当您运行 Java 程序时,输出只是此方法中的输出。所以你总是需要它!

关于java - 如何消除此消息错误 : Main method not found in class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26565214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com