参考文章:http://javacrazyer.iteye.com/blog/745761
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The expected argument types are (...) but the supplied types were (.., flex.messaging.io.amf.ASObject) and converted to ...
今天我用flex把数据写入数据库时出现了以上错误,具体错误信息如下:
body = (null)
clientId = "B22F4C72-1C0B-6EC1-38BD-1BD38C12157E"
correlationId = "3511E1F7-4186-A109-D816-A3EA69824AFF"
destination = "adminDAOImpl"
extendedData = (null)
faultCode = "Server.ResourceUnavailable"
faultDetail = "The expected argument types are (bean.Admin) but the supplied types were (flex.messaging.io.amf.ASObject) and converted to (null)."
faultString = "Cannot invoke method 'AddAdmin'."
headers = (Object)#1
messageId = "B22F4C74-8D09-3BAF-E17B-2D89965CF469"
rootCause = (mx.messaging.messages::ErrorMessage)#2
body = (null)
clientId = (null)
correlationId = (null)
destination = (null)
extendedData = (null)
faultCode = "Client.Message.Deserialize.InvalidType"
faultDetail = (null)
faultString = "Cannot convert type flex.messaging.io.amf.ASObject with remote type specified as 'null' to an instance of class bean.Admin"
headers = (Object)#3
messageId = "B22F4C74-8D1B-A98A-F69A-FA74FC38366F"
rootCause = (null)
timestamp = 1385729518045
timeToLive = 0
timestamp = 1385729518045
timeToLive = 0
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
错误截图如下:
---------------------------------------------------------------------------------------------------------------------------------------------------
根据错误信息可知在as对象转为java对象时发生了错误,我的java vo类代码如下:
package bean; public class Admin { //对应数据库表tbAdmin int id; String usrName; String usrPass; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsrName() { return usrName; } public void setUsrName(String usrName) { this.usrName = usrName; } public String getUsrPass() { return usrPass; } public void setUsrPass(String usrPass) { this.usrPass = usrPass; } }-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
我的as vo类代码如下:
package vo { public class Admin { public var id:int; public var usrName:String; public var usrPass:String; public function Admin()//构造函数 { } } }
服务器端往数据库写入java vo类对象的代码如下:
@Override public int AddAdmin(Admin admin) { //添加管理员 String sql="insert into tbAdmin(id,usrName,usrPass)" + " values (0?,'1?','2?')"; sql=sql.replace("0?",String.valueOf(admin.getId())); sql=sql.replace("1?",admin.getUsrName()); sql=sql.replace("2?",admin.getUsrPass()); System.out.println(sql); return DbCRUD.Add(sql); }
flex端调用远程对象的代码如下:
//增加用户 import vo.Admin;//导入包 protected function btnAdd_clickHandler(event:MouseEvent):void { //创建对象 var admin:Admin=new Admin(); admin.id=int(txbId.text); admin.usrName=txbUsrName.text; admin.usrPass=txbUsrPass.text; roAdmin.AddAdmin(admin);//调用远程对象 }
flex往数据库写入数据的步骤大致就是这样了,不料我执行以上代码时却出现了文章开始所说的错误,
为什么会出错呢?原来我们在定义as类时没有将其和远程java vo类关联起来,解决方法:
像下面这样定义as类即可:
package vo { [RemoteClass(alias="bean.Admin")] //这句不能少 public class Admin { public var id:int; public var usrName:String; public var usrPass:String; public function Admin()//构造函数 { } } }
注:
[RemoteClass(alias="这里写远程java vo类的全路径")] ,如:
[RemoteClass(alias="bean.Admin")]
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
您的十分满意是我追求的宗旨。
您的一点建议是我后续的动力。