2014-01-08 26 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

沒有'Object'構造函數接受'Reader'。 –

+0

請按照編譯器告訴你的說明!由於'Reader'沒有'(Object)'的構造函數 – Rugal

回答

3

你的類繼承只有Object類,它沒有一個方法或構造函數叫做openFile。如果您完全刪除super呼叫,您會沒事的。

1

此刻,您的類Buffin未指定超類;這意味着它有一個超類,那就是java.lang.Object。沒有任何構造函數在java.lang.Object中使用Reader

您可以在Buffin類中將Reader作爲字段存儲,也可以在構造函數中擴展接受一個的超類。

0

超級涉及超類的構造函數,我看到類Buffin不繼承任何類。正如@Sotirios Delimanolis所說,沒有構造函數接受Object in Object類中的Reader。