2013-09-12 3 views
0

Я, кажется, получаю сообщение об ошибке «Ошибка: int не может быть разыменован» при компиляции. Я искал причины, почему это происходит, и, несмотря на это, я не уверен, как я могу это исправить.Ошибка: int не может быть разыменован

public class NetID_BaseballPitcher 
{ 
    Scanner in = new Scanner(System.in); 
    private final int maxgames = 20; 
    private int[] gamesPitched = new int[maxgames]; 
    private int count, totalRuns; 
    private float totalInnings; 

    public int inputGameData() 
    { 
     for(int i = 0; i < count; i++) 
     { 
      gamesPitched[i] = new NetID_BaseballGame(); 
      gamesPitched[i].inputGame(); 
     } 
    } 
} 

А вот Baseballgame.java

public class NetID_BaseballGame 
{ 
    private static int runs; 
    private static int gameNum; 
    private static float innings; 
    public static void inputGame() 
    { 
     do 
     { 
      System.out.print("Game # "); 
      gameNum = in.nextInt(); 
     } while(gameNum < 0); 
     do 
     { 
      System.out.print("Number Innings"); 
      innings = in.nextInt(); 
     } while((innings < 0) && (innings > 10)); 

     do 
     { 
      System.out.print("Number Runs"); 
      runs = in.nextInt(); 
     } while(runs < 0); 
    } 
} 

При составлении BaseballPitcher.java, я получаю это:

NetID_BaseballPitcher.java:45: error: incompatible types 
      gamesPitched[i] = new NetID_BaseballGame(); 
         ^
    required: int 
    found: NetID_BaseballGame 
NetID_BaseballPitcher.java:46: error: int cannot be dereferenced 
     gamesPitched[i].inputGame(); 

Я предполагаю, что я что-то совершенно очевидно не хватает, и я просто вращаюсь там, где я нахожусь. Любая помощь будет принята с благодарностью!

ответ

1

Вы указали gamesPitched как массив значений int, но это не то, что вам нужно. Из требований, похоже, что вы должны объявить его как это:

private NetID_BaseballGame[] gamesPitched = new NetID_BaseballGame[MAX_GAMES]; 

Вам также необходимо инициализировать переменную count где-нибудь.

Смежные вопросы