Java中的异常错误汇总
2022/1/18 12:03:59
本文主要是介绍Java中的异常错误汇总,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
目录
1.使用rmi测试发生的异常
2.Mybatis执行sql语句参数错误
1.使用rmi测试发生的异常
java.rmi.server.ExportException: remote object implements illegal remote interface; nested exception is: java.lang.IllegalArgumentException: illegal remote method encountered: public abstract java.lang.String com.righteye.remote.IHello.sayHello(java.lang.String) at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:228) at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:383) at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:320) at java.rmi.server.UnicastRemoteObject.<init>(UnicastRemoteObject.java:198) at java.rmi.server.UnicastRemoteObject.<init>(UnicastRemoteObject.java:180) at com.righteye.remote.impl.IHelloImpl.<init>(IHelloImpl.java:10) at com.righteye.remote.impl.RmiServer.main(RmiServer.java:15) Caused by: java.lang.IllegalArgumentException: illegal remote method encountered: public abstract java.lang.String com.righteye.remote.IHello.sayHello(java.lang.String) at sun.rmi.server.Util.checkMethod(Util.java:267) at sun.rmi.server.Util.getRemoteInterfaces(Util.java:246) at sun.rmi.server.Util.getRemoteInterfaces(Util.java:216) at sun.rmi.server.Util.createProxy(Util.java:146) at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:226) ... 6 more
解决方案:
注册远程调用的服务需要 throws RemoteException
public interface IHello extends Remote { public String sayHello(String name) throws RemoteException; } public class IHelloImpl extends UnicastRemoteObject implements IHello { protected IHelloImpl() throws RemoteException { super(); } @Override public String sayHello(String name) throws RemoteException { return "Hello" + name; } }
2.Mybatis执行sql语句参数错误
org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: org.apache.ibatis.binding.BindingException: Parameter 'myname' not found. Available parameters are [arg1, arg0, param1, param2] ### The error may exist in com/righteye/day01/dao/UserDao.xml ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: insert into user(username, password) values(?, ?) ### Cause: org.apache.ibatis.binding.BindingException: Parameter 'myname' not found. Available parameters are [arg1, arg0, param1, param2]
解决方案:参数名不匹配问题,当传入多个参数的时候,可以使用对象的形式进行传参,使用对象属性名进行赋值;如果使用基本数据类型,可以在接口方法声明的参数前加上Param(自定义参数名) 给参数起别名
int insertUser(@Param("myname")String username, @Param("pwd")String password);
<insert id="insertUser"> insert into user(username, password) values(#{myname}, #{pwd}) </insert>
这篇关于Java中的异常错误汇总的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南
- 2024-09-30Dnd-Kit学习:新手快速入门指南