Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误消息";java.lang.NoSuchMethodError:客户。<;初始化>;(Ljava/lang/String;D)V“;_Java_Class_Object - Fatal编程技术网

错误消息";java.lang.NoSuchMethodError:客户。<;初始化>;(Ljava/lang/String;D)V“;

错误消息";java.lang.NoSuchMethodError:客户。<;初始化>;(Ljava/lang/String;D)V“;,java,class,object,Java,Class,Object,运行此程序时,我不断收到相同的错误消息。这就是我得到的: Exception in thread "main" java.lang.NoSuchMethodError: Customer.<init>(Ljava/lang/String;D)V at Customer5.input(Customer5.java:35)<b>---(See below (code) to refer to lines 35 & 7) at Customer5.main(Custo

运行此程序时,我不断收到相同的错误消息。这就是我得到的:

Exception in thread "main" java.lang.NoSuchMethodError: Customer.<init>(Ljava/lang/String;D)V 
at Customer5.input(Customer5.java:35)<b>---(See below (code) to refer to lines 35 & 7)
at Customer5.main(Customer5.java:7)
线程“main”java.lang.NoSuchMethodError中出现异常:Customer。(Ljava/lang/String;D)V 在Customer5.input(Customer5.java:35)--(参见下面的(代码)以参考第35行和第7行) 在Customer5.main(Customer5.java:7) 另一件事是类“Customer”显示一条消息,上面说“Customer类型已经定义”

import java.util.*;
公共类客户5{
公共静态void main(字符串[]args){
Customer[]customers=input();//这是第7行
客户=分类(客户);
输出(客户);
}
公共静态客户[]输入(){
扫描仪输入=新扫描仪(System.in);
int n;
字符串名;
双重债务;
System.out.print(“输入客户数量:”);
n=input.nextInt();
客户[]客户=新客户[n];

对于(inti=0;i测试,它对我来说很好

在IDE中找到“clear and build”(清除并构建)选项,它应该可以做到这一点



还要确保在您的项目中不存在其他客户类。

这个类对我来说运行良好,问题是您的包或应用程序中必须有其他一些客户类,它们没有构造函数
公共客户(字符串名称,双重债务)

尝试单击Ctrl+Shift+R并搜索客户或
按Ctrl+H,在所有java文件中搜索Customer

重新编译您的类和所有相关类。IDE将为您处理所有这些。问题是我有另一个Customer类。感谢您的反馈!也许这会帮助其他人:如果您不使用sur,则从旧库升级可能会导致此类异常,这也很好新库在运行的服务器上也可用。当您使用maven并将库声明为已提供时,可能会出现这种情况-这意味着您必须确保库在运行时可用。
import java.util.*;
public class Customer5 {

    public static void main(String[] args) {


        Customer[] customers=input();//This is line 7
        customers=sort(customers);
        output(customers);
    }


    public static Customer[] input(){

        Scanner input =new Scanner(System.in);
        int n;


        String name;
        double debt;


        System.out.print("Enter number of customers :");
        n=input.nextInt();

        Customer[] customers=new Customer[n];
        for(int i=0; i<n; i++){

            System.out.print("Enter name:");
            name=input.next();

            System.out.print("Enter debt:");
            debt=input.nextDouble();

            customers[i]=new Customer(name, debt);//This is line 35
        }
        return customers;
    }


    public static Customer[] sort(Customer[] customers){

        Customer temp;
        for(int i=0; i<customers.length; i++){

             for(int j=i+1; j<customers.length; j++){

                   if(customers[j-1].debt>customers[j].debt){

                         temp=customers[j-1];
                         customers[j-1]=customers[j];
                         customers[j]=temp;
                   }
             }
        }
              return customers;
    }



     public static void output(Customer[] customers){
            for(int i=0; i<customers.length; i++){
             System.out.println(customers[i].name+"\t" +customers[i].debt);
            }
     }



} 

class Customer{ //this line shows a message that says:The type Customer is already defined

    public String name;
    public Double debt;

    public Customer(String name, double debt){
       this.name=name;
       this.debt=debt;
    }

}