0

我会在我的班级中调用一个简单的线程,但是当我调用它时应用程序崩溃。这是线程:

private void startGame() {
    new Thread(new Runnable() {
        public void run() {
            while (isGiocoAttivo()) {
                try {
                    Thread.sleep(velocitaDiGioco);
                    accendiBomba();
                } catch (InterruptedException ex) {
                }
            }

        }
    }).start();
}

我该如何解决?accendiBomba 方法:

private void accendiBomba() {
    try {
        do {
            this.x = (int) Math.round(Math.random() * (righe - 1));
            this.y = (int) Math.round(Math.random() * (colonne - 1));
        } while (!this.action(this.x, this.y));
    } catch (CampoException ex) {
    }
}
4

1 回答 1

0

在您的线程中执行以下操作

private void startGame() {
new Thread(new Runnable() {
    public void run() {
        while (isGiocoAttivo()) {
            try {
                Thread.sleep(velocitaDiGioco);
               runOnUiThread(new Runnable() {

                @Override
                public void run() {

                    accendiBomba() 
                }
            });
            } catch (InterruptedException ex) {
            }
        }

    }
}).start();}
于 2013-07-02T14:38:51.597 回答