我正在通過OCA Java SE 7學習指南並正在通過包。不過,我在Eclipse中輸入了相同的代碼,但是我遇到了這個錯誤。 錯誤是線程「main」中的異常java.lang.NullPointerException - 包
異常線程 「main」 顯示java.lang.NullPointerException 在com.ocaj.exam.tutorial.MainClass.main(MainClass.java:12)
這裏是我的代碼...
package com.ocaj.exam.tutorial; //Package statement
//Imports class ArrayList from the java.util package
import java.util.ArrayList;
//Imports all classes from the java.io package
import java.io.*;
public class MainClass {
public static void main(String[] args) {
//Creates console from java.io package
Console console = System.console();
String planet = console.readLine("\nEnter your favourite planet: ");
//Creates list for planets
ArrayList planetList = new ArrayList();
planetList.add(planet); //Adds users input into the list
planetList.add("Gliese 581 c"); //Adds a string to the list
System.out.println("\nTwo cool planets: " + planetList);
}
}
非常感謝