Array of Classes NullPointerException

后端 未结 8 1750
悲&欢浪女
悲&欢浪女 2020-12-12 05:17

This is Element class:

public class Element {

    private String elementName;
    private int atomicNumber;
    private String Symbol;
    priv         


        
8条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 05:21

    Declaring an array like initialises the array object, but not the elements of the array. You need to create an Element object at each index of the array.

    element[0] = new Element();
    element[0].setElementName("H");
    

提交回复
热议问题