2
回答
java初学者,为什么会显示Source not found.谢谢
【腾讯云】校园拼团福利,1核2G服务器10元/月!>>>   
package pratice;
import java.util.*;

public class EqualsTest {
	
	static class  Class{
		private String name;
		private int age;
		private int number;
		private int grade;
		
		public Class(String n, int a,int u,int g){
			name=n;
			age=a;
			number=u;
			grade=g;
		}
		
		public String getName(){
			return name;
		}
		public int getAge(){
			return age;
		}
		public int getNumber(){
			return number;
		}
		public int grade(){
			return grade;
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		System.out.println("请输入班级人数");
		int counter=in.nextInt();
		Class a[]=new Class[counter];
		
		for(int c=0;c<=counter;c++){
			System.out.println("请输入姓名,年龄,学号,成绩");
			Class b=a[c];
			b.name=in.nextLine();
			b.number=in.nextInt();
			b.age=in.nextInt();
			b.grade=in.nextInt();
			
			if(b.name=="no"){
				break;
			}
			
		}
		for(Class b:a){
			System.out.println("姓名="+b.name);
			System.out.println("年龄="+b.age);
			System.out.println("学号="+b.number);
			System.out.println("成绩="+b.grade);
		}
	}

}

程序在运行后显示

Exception in thread "main" java.lang.NullPointerException at pratice.EqualsTest$Class.access$0(EqualsTest.java:7) at pratice.EqualsTest.main(EqualsTest.java:43)

Debug 后显示Sourse not found



举报
华政码农
发帖于3年前 2回/2K+阅
顶部