我正在获取Thread [main](暂停(在游戏中进入方法<init>))我无法在任何地方找到错误</init>

时间:2013-10-01 15:27:05

标签: java

Thread [main] (Suspended (entry into method <init> in Game))    
Game.<init>() line: 36  
Game.main(String[]) line: 134   

由于某种原因我一直收到这个错误,我无法理解。所有帮助赞赏

它说公共Game(){和新的Game()有一些错误.start();而我却找不到它

这是我的游戏文件:

package ca.vanzeben.game;

    import java.awt.BorderLayout;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferStrategy;
    import java.awt.image.BufferedImage;
    import java.awt.image.DataBufferInt;

    import javax.swing.JFrame;

    import ca.vanzeben.game.gfx.Screen;
    import ca.vanzeben.game.gfx.SpriteSheet;

    public class Game extends Canvas implements Runnable {

private static final long serialVersionUID = 1L;

public static final int WIDTH = 160;
public static final int HEIGHT = WIDTH /12*9;
public static final int SCALE = 3;
public static final String NAME = "Wake Me Up...";

private JFrame frame;

public boolean running = false;
public int tickCount = 0;

private BufferedImage image = new BufferedImage(WIDTH,HEIGHT,                BufferedImage.TYPE_INT_RGB);
private int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();

private Screen screen;

public Game() {
    setMinimumSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
    setMaximumSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
    setPreferredSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));

    frame = new JFrame(NAME);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());

    frame.add(this, BorderLayout.CENTER);
    frame.pack();

    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
public void init() {
    screen = new Screen(WIDTH,HEIGHT, new SpriteSheet("/SpriteSheet.png"));
}

public synchronized void start() {
    running = true;
    new Thread(this).start();

}

public synchronized void stop() {
    running = false;
}

public void run() {
    long lastTime = System.nanoTime();
    double nsPerTick = 1000000000D / 60D;

    int frames = 0;
    int ticks = 0;

    long lastTimer = System.currentTimeMillis();
    double delta = 0;

    init();

    while (running) {
        long now = System.nanoTime();
        delta += (now - lastTime)/nsPerTick;
        lastTime = now;
        boolean ShouldRender = true;

        while (delta >= 1) {
        ticks++;
        tick();
        delta -= 1;
        ShouldRender = true;
   }
        try {
            Thread.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (ShouldRender) {
        frames++;
        render();
        }

        if (System.currentTimeMillis()- lastTimer >= 1000){
            lastTimer += 1000;
            System.out.println(ticks+ "," +frames);
            frames = 0;
            ticks = 0;
        }
    }
}

public void tick() {
tickCount++;    

for (int i = 0; i <pixels.length; i++) {
pixels[i] = i + tickCount;
}
}

public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return;
    }

    screen.render(pixels, 0, WIDTH);

    Graphics g = bs.getDrawGraphics();
    g.drawImage(image, 0, 0, getWidth(), getHeight(),null);
    g.dispose();
    bs.show();
}

     public static void main(String[] args){ 
    new Game().start();
    }

正如我所说,所有帮助表示赞赏。它一直说有错误,我找不到它

2 个答案:

答案 0 :(得分:1)

您正在使用 Eclipse ,对吗?

您没有错误,只有方法入口断点。检查代码旁边的左侧栏。将有一个蓝色圆圈,带有刻度线和箭头。

您有多种选择:

  • 双击它,它应该消失(当然重新开始执行)
  • 右键单击,切换:断点消失
  • 右键单击,禁用:断点将在那里,但不活动
  • 使用运行(绿色播放按钮)代替调试(绿色小车按钮) - 断点保持原状,但不计入帐号
  • F8 :断点保持原状,执行一直持续到下一个断点

答案 1 :(得分:0)

这看起来不像是一个错误。您正在调试器或类似的开发工具中运行您的应用程序,似乎被指示通过断点或“停止实例创建”等规则在指定位置暂停您的程序。

您应该检查您的环境。使用普通java启动器运行不会产生这样的错误。