2014-03-26 1 views
5

이 프로그램을 실행할 때 계속 동일한 오류 메시지가 나타납니다. 이것은 내가 얻은 것입니다 :"java.lang.NoSuchMethodError : Customer. <init> (Ljava/lang/String; D) V"

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) 

"고객"클래스에는 "고객 유형이 이미 정의되었습니다."라는 메시지가 표시됩니다.

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; 
    } 

} 

나는 그것을 고치기 위해 무엇을해야할지 모르겠다. 이 유형의 오류 메시지에는 익숙하지 않습니다. 이 문제에 접근하는 방법에 대한 피드백이나 의견을 보내 주시면 감사하겠습니다. 감사!

+3

이 클래스와 관련된 모든 클래스를 다시 컴파일 Ctrl 키 + 시프트 + R을 눌러 시도하고 모든 자바 파일에 고객 또는 에서 Ctrl + H, 검색 고객을 검색 할 수 있습니다. –

+0

IDE가이 모든 것을 처리합니다. – chrylis

답변

11

테스트를 마친 후 정상적으로 작동합니다.

IDE에서 "지우기 및 빌드"옵션을 찾으면 트릭을 수행해야합니다.


또한 프로젝트에 다른 고객 클래스가 존재하지 않는지 확인하십시오.

+0

문제는 다른 고객 클래스가 있다는 것입니다. 귀하의 의견에 감사드립니다! – SdlS

3

이 클래스는 저에게 잘 돌아갑니다. 패키지 또는 응용 프로그램에 생성자 public Customer(String name, double debt)이있는 다른 Customer 클래스가 있어야합니다.

관련 문제