2014-12-13 55 views
-2

我開始深入到我的世界小遊戲插件,我最近開始一個團隊死亡遊戲插件,它需要一個線程保持一個倒計時鐘運行。定時器線程的代碼保存在GameTimer類,它是由startGame方法調用Game類啓動。 的Eclipse口口聲聲說「start方法是未定義的類型GameTimer」,這是奇怪的考慮到GameTimer類實現Runnable接口,並在遊戲類實例化Eclipse的線程錯誤

的GameTimer方法看起來像這樣:

package game.start.time; 

public class GameTimer implements Runnable { 

    //Initial arguments for setting length of game in minutes and seconds 
    //Stored as reference and are not modified 
    int gameMinutes; 
    int gameSeconds; 

    //values for minutes and seconds to be used by the time thread 
    int minutes; 
    int seconds; 

    // value to denote if time is up for te game or not 
    boolean timeDone; 

    //constructor 
    public GameTimer(int minutesIn){ 

     gameMinutes = minutesIn; 

     gameSeconds = 0; 

     minutes = minutesIn; 

     seconds = 0; 

    } 


    //returns a formatted string that prints the time in clock format 
    public String printTime(int minutes, int seconds){ 

     if(seconds<10){ 

      return String.format("%d:0%d",minutes,seconds); 
     }else{ 

      return String.format("%d:%d",minutes,seconds); 

     } 

    } 


    //thread which counts down time 
    @Override 
    public void run() { 


     try { 
      String toPrint = printTime(minutes,seconds); 

      seconds--; 

      if(seconds==0){ 

       seconds = 59; 
       minutes--; 
      } 

       if(minutes == 0 && seconds == 0){ 

        setTimeUp(true); 

       } 
     } catch (Exception e) { 

      e.printStackTrace(); 
     } 

     } 


     //sets timeIsUp value 
     public void setTimeUp(boolean timeIsUp){ 

      timeDone = timeIsUp; 



    } 

    //passes timeIsUp value to calling methods 
    public boolean getTimeDone(){ 


     return true; 
    } 



    } 

而且StartGame方法看起來像這樣:

package game; 

import game.start.time.GameTimer; 



public class Game { 

    public boolean teamsRegistered; 
    public boolean spawnPointsRegistered; 
    public boolean gameTimeSet; 
    int gameTime; 

    GameTimer timer = new GameTimer(gameTime); 

    public Game(int gameTimeIn){ 

     gameTimeSet = true; 
     gameTime = gameTimeIn; 

    } 

    public void startGame(){ 

     timer.start(); 

    } 



} 

編輯***以下是錯誤的圖片:

http://prntscr.com/5g7zdw

+0

請** **沒有鏈接到錯誤的圖片。而是在您的問題中發佈您的實際和完整錯誤文本。 – 2014-12-13 02:48:33

+0

你不能只用'run'和'start'互換(!看的方法) – August 2014-12-13 02:49:26

+0

這是** **不是一個Eclipse錯誤,實際上我們的問題絕對沒有任何與Eclipse做([標籤: eclipse]標籤被刪除)。這是一個Java編譯器錯誤信息,警告你,你試圖調用一個不存在的方法。 Runnable的是,有一個方法,'的run()'的接口,僅此而已,並實現Runnable的類必須實際實現的方法。你可能會考慮學習一本介紹Java的基本書,因爲這對你非常有幫助。 – 2014-12-13 02:52:11

回答