我的java程序正在创建27个无效错误

时间:2014-04-22 11:23:06

标签: java compiler-errors

当我运行这些我的java代码行时,它给了我27个错误,而不是实际错误

for(int counter = 0;counter<teamName.size();counter++)
  {
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
  System.out.println();
  }

aLeaderboard是一个带有自定义类Leaderboard的ArrayList。它是20长,teamName也是一个20长的ArrayList。

ArrayList<Leaderboard> aLeaderboard = new ArrayList<Leaderboard>();

它产生了这些错误:

D:\>javac Project4.java
Project4.java:216: error: illegal start of type
  for(int counter = 0;counter<teamName.size();counter++)
  ^
Project4.java:216: error: ')' expected
  for(int counter = 0;counter<teamName.size();counter++)
                 ^
Project4.java:216: error: illegal start of type
  for(int counter = 0;counter<teamName.size();counter++)
                    ^
Project4.java:216: error: <identifier> expected
  for(int counter = 0;counter<teamName.size();counter++)
                     ^
Project4.java:216: error: ';' expected
  for(int counter = 0;counter<teamName.size();counter++)
                      ^
Project4.java:216: error: > expected
  for(int counter = 0;counter<teamName.size();counter++)
                                      ^
Project4.java:216: error: <identifier> expected
  for(int counter = 0;counter<teamName.size();counter++)
                                                     ^
Project4.java:216: error: illegal start of type
  for(int counter = 0;counter<teamName.size();counter++)
                                                       ^
Project4.java:216: error: <identifier> expected
  for(int counter = 0;counter<teamName.size();counter++)
                                                        ^
Project4.java:217: error: ';' expected
  {
   ^
Project4.java:218: error: illegal start of type
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
        ^
Project4.java:218: error: ';' expected
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
            ^
Project4.java:218: error: invalid method declaration; return type required
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
             ^
Project4.java:218: error: illegal start of type
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                   ^
Project4.java:218: error: ')' expected
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                    ^
Project4.java:218: error: ';' expected
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                           ^
Project4.java:218: error: illegal start of type
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                              ^
Project4.java:218: error: <identifier> expected
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                               ^
Project4.java:218: error: ';' expected
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                                ^
Project4.java:218: error: illegal start of type
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                                   ^
Project4.java:218: error: <identifier> expected
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                                        ^
Project4.java:218: error: ';' expected
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                                          ^
Project4.java:218: error: illegal start of type
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                                                    ^
Project4.java:218: error: <identifier> expected
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                                                                ^
Project4.java:218: error: ';' expected
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
                                                                 ^
Project4.java:219: error: <identifier> expected
  System.out.println();
                    ^
Project4.java:221: error: class, interface, or enum expected
}
^
27 errors

D:\>

teamName包含20个字符串,这些字符串都是单个字。

1 个答案:

答案 0 :(得分:0)

此代码是否在方法之外?

尝试用以下代码替换当前代码:

public static test() {
for(int counter = 0;counter<teamName.size();counter++)
  {
  System.out.print((counter + 1) + "   " +  teamName.get(counter) + "   " + (aLeaderboard.get(counter)).getGamesPlayed() + "   " + (aLeaderboard.get(counter)).getHomeWins() + "   " +  (aLeaderboard.get(counter)).getHomeDraws() + "   ");
  System.out.println();
  }
}