2013-02-27 1 views
0

, 내 코드는 컴파일 할 수 없습니다 : Java - 생성자를 찾을 수 없습니까? 컴파일하려고 할 때

package ch02.genericStringLogs; 

public class DemoGenericLogs { 
    public static void main(String[] args) { 
    GenericLogInterface<Float> genFloatLog = new LinkedGenericLog<Float>(); 
    LLGenericNode<Float> node0 = new LLGenericNode<Float>(2.2); 
    LLGenericNode<Float> node1 = new LLGenericNode<Float>(3.3); 
    LLGenericNode<Float> node2 = new LLGenericNode<Float>(4.4); 
    LLGenericNode<Float> node3 = new LLGenericNode<Float>(5.5); 
    genFloatLog.insert(node0); 
    genFloatLog.insert(node1); 
    genFloatLog.insert(node2); 
    genFloatLog.insert(node3); 

    System.out.println(genFloatLog.size()); 
    System.out.println(genFloatLog.toString()); 
    genFloatLog.clear(); 
    System.out.println(genFloatLog.size()); 

    GenericLogInterface<String> genStringLog = new LinkedGenericLog<String>(); 
    LLGenericNode<String> string0 = new LLGenericNode<String>("one"); 
    LLGenericNode<String> string1 = new LLGenericNode<String>("two"); 
    LLGenericNode<String> string2 = new LLGenericNode<String>("three"); 
    LLGenericNode<String> string3 = new LLGenericNode<String>("four"); 

    System.out.println(genStringLog.size()); 
    System.out.println(genStringLog.toString()); 
    genStringLog.clear(); 
    System.out.println(genStringLog.size()); 
    } 
} 

내가이 오류를 얻을 :

Error: 
    part1/ch02/genericStringLogs/DemoGenericLogs.java:5: cannot find symbol 
    symbol : constructor LinkedGenericLog() 
    location: class ch02.genericStringLogs.LinkedGenericLog<java.lang.Float> 
+5

다음과 같이 : LinkedGenericLog 클래스에 대한 인수 생성자를 찾을 수 없습니다 ... 그리고 그 클래스를 표시하지 않으므로 더 많은 것을 말하기는 어렵습니다. – assylias

+0

'LinkedGenericLog' 클래스가 있습니까? 같은 패키지에 수업이 있나요? –

+0

예. 여기에 나열된 파일과 동일합니다. http://stackoverflow.com/questions/15122613/java-compile-time-error-compiler-not-recognizing-method-override – user1696035

답변

1

이 줄을 ...

GenericLogInterface<String> genStringLog = new LinkedGenericLog<String>(); 

당신이 시도하고 있음을 나타냅니다 인수가없는 생성자를 호출합니다.

LinkedGenericLog 클래스에는 오류가 발생하는 경우 인수가없는 생성자가 없어야합니다. Java provides one by default, 인수를 취하는 다른 생성자를 정의하지 않는 한.

+1

또는 액세스 할 수 없습니다. – assylias

3

그것은 당신의 earlier question에서와 같은 클래스의 가정 LinkedGenericLog<T>의 유일한 생성자는 이것이다 : 당신이 하나를 구성 할 때

public LinkedGenericLog(String name) 

그래서, 당신은 이름을 전달해야합니다. 예를 들어 당신이 이름을 통과해야하고 싶지 않은 경우

GenericLogInterface<Float> genFloatLog = new LinkedGenericLog<Float>("Some name"); 

, 당신은 LinkedGenericLog을 변경해야 - 매개 변수없는 생성자를 추가합니다. 이 경우 로그에 어떤 이름을 지정 하시겠습니까?

+0

내가 명명 한 확인이 ("노드") LinkedGenericLog 하지만 지금은 다음 줄에 오류가 발생 자바 : 6 : 생성자 LLGenericNode (더블) 위치 : 클래스 ch02.genericStringLogs.LLGenericNode <기호 기호를 찾을 수 없습니다 java.lang.Float> – user1696035

+0

같은 것. 매개 변수로 double을 사용하는 LLGenericNode의 생성자가 필요합니다. –

+0

괜찮 으면 어디에서 오는 이중입니까? – user1696035

관련 문제