简体   繁体   English

错误“构造函数 HighScore(int,int,String) 未定义”( game = new HighScore((id, score, user); )

[英]Error "the constructor HighScore(int,int,String)is undefined" ( game = new HighScore((id, score, user); )

when run the code is shown the constructor HighScore(int, int, String)is undefined"运行代码时显示构造函数 HighScore(int, int, String) 未定义”

import java.util.Scanner;

public class HighScore{

    public static HighScore readGameScore(Scanner sc){
        HighScore game;
        String user;
        int id;
        int score;

        System.out.print("Enter game user: ");
        user=sc.nextLine();
        System.out.print("Enter game ID: ");
        id=sc.nextInt();

        do{
            System.out.print("Enter game score: ");
            score=sc.nextInt();
            if(score<0){
                System.out.println("Please enter a valid value. ");
            }
        }while(score<0);
        *game = new HighScore(id, score, user);*
        return game;
    }
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        HighScore game;

        System.out.println("Enter your game score info!");
        game = readGameScore(sc);
        System.out.println("You entered: ");
        System.out.println(game);
        }
 }

So your class has no constructor defined so the compiler produces a default constructor under the hood ie所以你的 class 没有定义构造函数所以编译器在引擎盖下生成一个默认构造函数即

public HighScore(){}

you need one defined like你需要一个像这样定义的

public HighScore(int id, int score, String user){
......
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM