gpt4 book ai didi

java - Java编译错误: Exception in thread “main” java.lang.VerifyError:

转载 作者:行者123 更新时间:2023-12-02 11:07:43 24 4
gpt4 key购买 nike

我在运行代码时收到此错误,但不确定在这里出了什么问题:

Exception in thread "main" java.lang.VerifyError: (class: first3weeks/Main, method: <init> signature: ()V) Constructor must call super() or this()
Java Result: 1

学生代码:
package first3weeks;   

public class Student {
private String name, id;
private int[] score = new int[3];


public Student(){}

public Student(String stName, String stID, int stScore[]){
name = stName;
id = stID;
score = stScore;
}

public void setName(String nameIn){
name = nameIn;
}

public void setID(String idIn){
id = idIn;
}

public void setScore(int scoreIn[]){
score = scoreIn;
}

public String getName(){
return name;
}

public String getID(){
return id;
}

public int[] getScore(){
return score;
}

public double avScore(){
double total = score[1] + score[2] + score[3];
return (total/3);
}

public void printOut(){
System.out.println("Student Name: " + getName() + "\n" + "Student ID: " + getID() + "\n" + "Student Average: " + avScore());
}
}

主类:
package first3weeks;

public class Main {

public static void main(String[] args) {
int[] score1 = {12,15,19};
int[] score2 = {32,65,29};
Student stud1 = new Student("Rob", "001", score1);
Student stud2 = new Student("Jeff", "002", score2);
stud1.printOut();
stud2.printOut();

Student stud3 = new Student();
int[] score3 = {56,18,3};
stud3.setName("Richard");
stud3.setID("003");
stud3.setScore(score3);
stud3.printOut();
}
}

最佳答案

这个错误

Exception in thread "main" java.lang.VerifyError: (class: first3weeks/Main, 
method: <init> signature: ()V) Constructor must call super() or this()

表示未正确生成字节码。这可能是编译器中的错误。我将确保您具有Java 7更新40或Java 6更新45的最新更新。

关于java - Java编译错误: Exception in thread “main” java.lang.VerifyError:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19346590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com