做了一个如下的interfacepublic interface OnlineSystem_Interface { void storeRecord(String XMLSource, int recId); String retrieveRecord(int recId); void setDate(String date, int recId); void updateRecord(int recId); String setUpdateDate(String date);}然后又做了一个类实现这个interfacepublic class Adapter implements OnlineSystem_Interface{
。。
}主类里面生成了如下的interface对象public class Client { private OnlineSystem_Interface document; public Client() { this.document = new Adapter(); }
}但是, 请问, 为何this.document = new Adapter();这句报错?
报Type mismatch: cannot convert from Adapter to OnlineSystem_Interface请指点, 谢谢
。。
}主类里面生成了如下的interface对象public class Client { private OnlineSystem_Interface document; public Client() { this.document = new Adapter(); }
}但是, 请问, 为何this.document = new Adapter();这句报错?
报Type mismatch: cannot convert from Adapter to OnlineSystem_Interface请指点, 谢谢
看看是不是有拼写错误,clean一下,rebuild一下再看
//
class Adapter implements OnlineSystem_Interface{
public void storeRecord(String XMLSource, int recId){
} public String retrieveRecord(int recId){
return null;
} public void setDate(String date, int recId){
} public void updateRecord(int recId){
} public String setUpdateDate(String date){
return null;
}
} // 主类里面生成了如下的interface对象 public class Client { private OnlineSystem_Interface document; public Client() { this.document = new Adapter(); }
} // 但是, 请问, 为何this.document = new Adapter();这句报错?
// 报Type mismatch: cannot convert from Adapter to OnlineSystem_Interface
没错啊?????,再把接口前的public 去掉
It reads a source xml file as input and it invokes methods defined in the
OnlineSystem_Interface Interface on an class that implements that interface */import java.io.*;
import java.util.Scanner;import com.sun.xml.internal.bind.v2.model.core.Adapter;public class Client { // Define a document object of type OnlineSystem_Interface
private OnlineSystem_Interface document; // The Client constructor
public Client() { // Instanciate the document object with a class that implements the
// Org_A_Doc_Interface
this.document = new Adapter(); } // The Main Method
public static void main(String Args[]) { // Instantiate a Client Object
Client client = new Client(); // Create a string to store user input
String inputFile = null;
System.out.print("Input file name: "); // Read the Source xml file name provided as a command line argument
Scanner scanner = new Scanner(System.in);
inputFile = scanner.next(); // Create a string to store user input
String recId = null;
System.out.print("Input record ID: "); // Read the Source xml file name provided as a command line argument
recId = scanner.next(); //Convert the String recId to an integer value
int intRecID = Integer.parseInt(recId); if (inputFile != null && !inputFile.equals("")) { // Create and empty string to store the source xml file
String file = ""; try {
// Open the file
FileInputStream fstream = new FileInputStream(inputFile); // Convert our input stream to a
// BufferedReader
BufferedReader d = new BufferedReader(new InputStreamReader(
fstream)); // Continue to read lines while
// there are still some left to read
String temp = "";
while ((temp = d.readLine()) != null) {
// Add file contents to a String
file = file + temp;
}
d.close(); // The Client Calls the storeRecord Method on the Client.Document
// object
if (!file.equals("")) {
client.document.storeRecord(file, intRecID);
} } catch (Exception e) {
System.err.println("File input error");
} } else
System.out.println("Error: Invalid Input"); }}
private Admin_DataMgr dataManager;
private Admin_UpdateMgr updateManager;
private FileDetailsProvider fp;
Adapter(){
fp= FileDetailsProvider.getInstance();
fp.loadConfigFile("C:\\assignment5\\XMLTransformerConfig.xml");
dataManager = new Admin_DataMgr();
updateManager = new Admin_UpdateMgr();
}
public void storeRecord(String XMLSource, int recId){
dataManager.addRecord(XMLSource, recId);
} public String retrieveRecord(int recId){
return dataManager.getRecord(Integer.toString(recId));
} public void setDate(String date, int recId){
dataManager.setRecordDate(date, recId);
}
public void updateRecord(int recId){
updateManager.updateRecord(Integer.toString(recId));
} public String setUpdateDate(String date){
return updateManager.setLastUpdateDate(date);
}
}