首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

不能转换interface 被实现的类?解决思路

2012-01-11 
不能转换interface 被实现的类???做了一个如下的interfacepublic interface OnlineSystem_Interface {void

不能转换interface 被实现的类???
做了一个如下的interface

public 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);

}



然后又做了一个类实现这个interface

public 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

请指点, 谢谢


[解决办法]
看着好像没错啊
[解决办法]
答:从你现在给出的已有代码来看,这是不可能的.因此:错误肯定是由程序其它地方的代码引起的.
[解决办法]
要不你的Adapter就没有implements接口OnlineSystem_Interface
看看是不是有拼写错误,clean一下,rebuild一下再看
[解决办法]
我的eclipse 没有报错。
[解决办法]
使用的是windows系统不?用资源管理器(win+E)打开你的包结构,展开所有包,,,把类的结构分部情况粘到这里。让大家看下你的包里边的类的分部情况,另外把public class Client这个类的所有代码全部粘在这里来。你给的信息量太少了,不能找到问题。你给的代码如果包引用正确的是,是没错的。。。。
[解决办法]
import com.sun.xml.internal.bind.v2.model.core.Adapter; 

当然会错了,你导入的类是错误的。
[解决办法]
搞定啦,高手还是有的,牛奶也是有的呀!

热点排行