我遇到了一系列我无法弄清楚的错误。
Syntax Error on token "myBook", VariableDeclaratorId expected after this token.
Syntax Error on token "myMovie", VariableDeclaratorId expected after this token.
Syntax Error on token "myGame", VariableDeclaratorId expected after this token.
代码段如下:
package src.edu.htc.java1.library;
import java.util.ArrayList;
/**
*
*/
/**
* This class is used to test our library and media classes.
*
*/
public class MediaTester {
/**
* This is the main test method
* @param args - values passed in by the JVM when running
* the application
*/
public static void main(String[] args) {
Book myBook = new Book();
myBook.setLibraryId(123456L);
myBook.setLocation("Eden Prairie");
myBook.setTitle("My Book Title");
ArrayList<String> authorList = new ArrayList<String>();
authorList.add("Joe Author");
authorList.add("Jane Author");
myBook.setAuthors(authorList);
myBook.setCopyright("1984");
myBook.setFormat("paperback");
myBook.setNumberOfPages(385);
myBook.setPublishers("Some Publisher");
System.out.println(myBook);
Movies myMovie = new Movies();
myMovie.setTitle("Fargo");
myMovie.setReleaseDate(2123);
myMovie.setDirector("Jie Wu");
myMovie.setActors("Jessie");
myMovie.setMPAA_rating("R");
ArrayList<String> actors = new ArrayList<String>();
actors.add("Tom Hanks");
System.out.println(myMovie);
Games myGames = new Games();
myGames.setTitle("Starcraft");
myGames.setConsoleType("wii");
myGames.setEsbnRatings("E");
myGames.setReleaseDate("2012");
myGames.setPublishers("Blizzard");
System.out.println(myGames);
}
ArrayList<Media> myMediaList = new ArrayList<Media>();
myMediaList.add(myBook);
myMediaList.add(myMovie);
myMediaList.add(myGame);
Library myLibrary = new Library();
for (Media item : myMediaList) {
myLibrary.addToCollection(item);
System.out.println(item);
}
}
}
答案 0 :(得分:0)
您有一个额外的括号错误地放置了指定区域之外的所有代码。试试这个:
*请注意,我刚删除了以下括号:
System.out.println(item);
}
package src.edu.htc.java1.library;
import java.util.ArrayList;
/**
* This class is used to test our library and media classes.
*
*/
public class MediaTester {
/**
* This is the main test method
* @param args - values passed in by the JVM when running
* the application
*/
public static void main(String[] args) {
Book myBook = new Book();
myBook.setLibraryId(123456L);
myBook.setLocation("Eden Prairie");
myBook.setTitle("My Book Title");
ArrayList<String> authorList = new ArrayList<String>();
authorList.add("Joe Author");
authorList.add("Jane Author");
myBook.setAuthors(authorList);
myBook.setCopyright("1984");
myBook.setFormat("paperback");
myBook.setNumberOfPages(385);
myBook.setPublishers("Some Publisher");
System.out.println(myBook);
Movies myMovie = new Movies();
myMovie.setTitle("Fargo");
myMovie.setReleaseDate(2123);
myMovie.setDirector("Jie Wu");
myMovie.setActors("Jessie");
myMovie.setMPAA_rating("R");
ArrayList<String> actors = new ArrayList<String>();
actors.add("Tom Hanks");
System.out.println(myMovie);
Games myGames = new Games();
myGames.setTitle("Starcraft");
myGames.setConsoleType("wii");
myGames.setEsbnRatings("E");
myGames.setReleaseDate("2012");
myGames.setPublishers("Blizzard");
System.out.println(myGames);
ArrayList<Media> myMediaList = new ArrayList<Media>();
myMediaList.add(myBook);
myMediaList.add(myMovie);
myMediaList.add(myGame);
Library myLibrary = new Library();
for (Media item : myMediaList) {
myLibrary.addToCollection(item);
System.out.println(item);
}
}
}
}