这是Element
类:
public class Element {
private String elementName;
private int atomicNumber;
private String Symbol;
private double atomicWeight;
public Element()
{
}
public String getElementName()
{
return elementName;
}
public int getAtomicNumber()
{
return atomicNumber;
}
public String getSymbol()
{
return Symbol;
}
public double getAtomicWeight()
{
return atomicWeight;
}
public void setElementName(String elementName)
{
this.elementName = elementName;
}
public void setAtomicNumber(int atomicNumber)
{
this.atomicNumber = atomicNumber;
}
public void setSymbol(String Symbol)
{
this.Symbol = Symbol;
}
public void setAtomicWeight(double atomicWeight)
{
this.atomicWeight = atomicWeight;
}
}
我正在尝试参加Array
这个课程,这是我的mainU.java
课程:
public class mainU {
public static void main(String[] args){
Element[] element = new Element[103];
element[0].setElementName("H");
String s = element[0].getElementName();
System.out.println(s);
}
问题是我收到了这个错误:
Exception in thread "main" java.lang.NullPointerException
at mainU.main(mainU.java:14)
任何人都可以告诉我我收到这样一个错误的原因吗?我使我的程序尽可能简单,以便您能够帮助我。