我以正确的格式放置了我的 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/