关于Java中的java.lang.NullPointerException问题。 10
packagestudent_system_new;publicclassStudent{publicStudent(){this.studentID=0;this.Na...
package student_system_new;public class Student { public Student() { this.studentID = 0; this.Name = ""; Math = 0.0; Chinese = 0.0; English = 0.0; } public Student(int studentID, String name, double math, double chinese, double english) { this.studentID = studentID; this.Name = name; Math = math; Chinese = chinese; English = english; } private int studentID; private String Name; private double Math; private double Chinese; private double English; public void setName(String name) { Name = name; } public void setStudentID(int ID) { studentID = ID; } public void setMath(double math) { Math = math; } public void setChinese(double chinese) { Chinese = chinese; } public void setEnglish(double english) { English = english; }}package student_system_new;import java.util.*;public class Classes { public Classes() { super(); } final static int SIZE = 5; private Student[] class1 = new Student[SIZE]; public void setData() { System.out.println("输入学生数据:学号、姓名、数学、语文、英语"); Scanner data = new Scanner(System.in); for(Student a: class1) { a.setStudentID(data.nextInt()); a.setName(data.next()); a.setMath(data.nextDouble()); a.setChinese(data.nextDouble()); a.setEnglish(data.nextDouble()); } data.close(); }}package student_system_new;public class Texter { public static void main(String[] args) { // TODO Auto-generated method stub Classes first = new Classes(); first.setData(); }}有三个类。我测试setData目的是想输入五个学生数据,可是输入的时候出现了如下图这样的错误,好像是使用了一个空指针,是不是数组这里有问题?该怎么改呢?
展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询