2014-01-08 4 views
0

슈퍼 문을 올바른 형식으로 넣었습니다. 그러나 유일한 오류는 클래스 java.lang.object의 생성자 객체가 코드의이 부분에 대해 지정된 유형에 적용될 수 없다는 것입니다.내 슈퍼 문을 어떻게 수정합니까?

 super (openFile (filename)); 

여기 지금 내 현재 코드입니다 :

 import java.io.BufferedReader; 
    import java.io.ByteArrayOutputStream; 
    import java.io.File; 
    import java.io.FileNotFoundException; 
    import java.io.FileReader; 
    import java.io.IOException; 
    import java.io.OutputStream; 
    import java.io.OutputStreamWriter; 
     import java.security.MessageDigest; 
     import java.security.NoSuchAlgorithmException; 
     import java.util.Vector;import java.io.PrintWriter; 
     import java.io.BufferedWriter; 
     import java.io.FileWriter; 
     import java.io.InputStream; 
     import java.io.InputStreamReader; 
     import java.io.Reader; 

     public class Buffin 
     {    
private static boolean temp; 
///////////////////////////////// 
private boolean isKeyboard; 


/** Connect to the disk file with the given name. If this 
    * cannot be done, connect to the keyboard instead. */ 

public Buffin (String filename) 
{ super (openFile (filename)); 
     isKeyboard = temp; 
} //====================== 


private static Reader openFile (String filename) 
{ try 
     { temp = false; 
      return new FileReader (filename); // IOException here 
     }catch (IOException e) 
     { temp = true; 
      return new InputStreamReader (System.in); 
     } 
} //====================== 


/** Read one line from the file and return it. 
    * Return null if at the end of the file. */ 

public String readLine() 
{ if (isKeyboard) 
     { System.out.print (" input> "); 
      System.out.flush(); // flush the output buffer 
     } 
     try 
     { return super.readLine(); // in BufferedReader 
     }catch (IOException e) 
     { System.out.println ("Cannot read from the file"); 
      return null; 
     } 
} //============ 
}[/code] 
+0

'Reader'를 받아들이는'Object' 생성자가 없습니다. –

+0

컴파일러에서 알려주는 지침을 따르십시오! 'Reader'는'(Object)'를 가진 생성자가 없기 때문에 – Rugal

답변

3

클래스 만 Object 클래스를 확장, 그리고 메소드 또는 생성자 openFile라고하지 않습니다. super 전화를 모두 삭제해도 문제가 없습니다.

1

현재 Buffin 클래스는 수퍼 클래스를 지정하지 않습니다. 그건 하나의 수퍼 클래스를 가지고 있고 그게 java.lang.Object이라는 것을 의미합니다. java.lang.Object에는 Reader을 사용하는 생성자가 없습니다.

Buffin 클래스에 Reader을 필드로 저장할 수도 있고, 생성자에서 수퍼 클래스를 허용하는 수퍼 클래스를 확장 할 수도 있습니다.

0

슈퍼는 슈퍼 클래스의 생성자와 관련이 있습니다. 클래스 버퍼는 클래스를 상속받지 않습니다. @Sotirios Delimanolis에 따르면, Object 클래스에서 Reader를 허용하는 생성자가 없습니다.