Android,Handler的错误

时间:2011-10-03 02:01:09

标签: android multithreading handler

这有点奇怪,但我不知道问题出在哪里。

在我的onCreate()中,我有这段代码:

GameRunningNotesTimer().start();

然后离开onCreate我有这个代码:

Thread GameRunningNotesTimer = new Thread(new Runnable() { 

    public void run() {

        int sleepingTime;
        try {
            if (r_settings.getGameOver() == 0) {

                sleepingTime = 1000 - (r_settings.getInternalLevel() * 100);

                if (r_settings.getInternalLevel() == 0) {
                    Thread.sleep(1000); 
                } else {
                            if (sleepingTime <= 399) 
                            {
                                sleepingTime = 350;
                            }
                            Thread.sleep(sleepingTime);
                        }
                    if (r_settings.getGameOver() == 1){ gameOver(); }

                myHandler2.sendEmptyMessage(0);
            } // End of if (r_settings.getGameOver()
        } catch (Exception e) { Log.e("MUSIC!!!!!", "Error in activity", e); }
    }// End of run
}); // End of GameRunningNotesTimer()




final Handler myHandler2 = new Handler() {

    @Override
    public void handleMessage(Message msg) {

        //text2.setText(""+item[0]);
        int z = 1;

        if (r_settings.getGameStarted() == true)
        {
            changeNoteFromTimer(); 
        } else {
            startingCountdown(z);
        } 

    } // end of handleMessage()

};

但是 GameRunningNotesTimer ()。start();带有红色下划线(在Eclipse中),当我鼠标悬停时,它会显示:The method GameRunningNotesTimer() is undefined for the type GameScr

我做错了什么?同一个类中的另一个线程/处理程序没有给我这个问题。

谢谢!

1 个答案:

答案 0 :(得分:2)

应该是GameRunningNotesTimer.start(); 不是 GameRunningNotesTimer().start();