java - 如何修复我的 super 报表?

标签 java super bluej

我以正确的格式放置了我的 super 语句,但我唯一的错误是它指出类 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]

最佳答案

您的类仅扩展 Object 类,并且没有名为 openFile 的方法或构造函数。如果完全删除 super 调用,那就没问题了。

关于java - 如何修复我的 super 报表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20986353/

相关文章:

java - 如何使用java中的正则表达式检查给定sql查询中子句的正确顺序?

Java使用嵌套循环打印数组

java - 自从我添加了 super 关键字后,代码就没有输出任何内容

java - 从数组列表中删除一个 block

java - System.out 和 .err - 回到 future ?

python - 在派生类中调用 super() 时,可以传入 self.__class__ 吗?

Python super() 传入 *args

java - 过载错误?

java - BlueJ 二维数组

java - 了解使用二进制补码写入 bluej 的程序。