Array of Classes NullPointerException

后端 未结 8 1744
悲&欢浪女
悲&欢浪女 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:28

    You have not initialized element[0] . You need to initialize it first, in fact every array element if you intent to use them.

    element[0]=new Element();
    

    or you can initialize all of them using loop

      for(int i=0;i

提交回复
热议问题