可能重複:
NullPointerException when Creating an array of object數據結構
我有在主方法的NullPointerException中,管線
array[0].name = "blue";
結構類別:
public class Items {
String name = "";
String disc = "";
}
主類:
public class ItemsTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Items[] array = new Items[2];
array[0].name = "blue"; //NullPointerException
array[0].disc = "make";
array[1].name = "blue";
array[1].disc = "blue";
}
}
請幫助我如何解決這個問題。
另一個:http://stackoverflow.com/questions/4067286/java-nullpointerexception-in-array – 2012-07-18 09:56:22
另一個:http://stackoverflow.com/questions/8145728/nullpointerexception-being-thrown-whenever-array -member-是訪問的 – 2012-07-18 09:58:42