常见异常

本文详细介绍了Java网络通信异常、J2EE表单处理异常、SSH事务管理异常、Struts配置错误、服务器端口冲突及数据库命令行错误的解决方法。包括检查端口号、配置文件、操作对象状态、SQL语句参数、类映射等问题,帮助开发者高效定位并解决异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解决异常的方法:

          

============================================J2SE异常========================================= 

java.net.ConnectException: Connection refused: connect

 异常描述:这个异常发生在网络通信的套接字使用中。

 解决方法: 

                1) 当前服务器端口不可用。可通过运行cmd -> netstat -nao查看当前可用端口号。
                2) 必须先运行服务器再运行客户端,次序不能颠倒,也就是必须先有接收的。

 

============================================J2EE异常========================================= 

注意如果s:iterator中的值做为条件不是利用超链接的形式传递过去的,而是作为表单的一部分的时候,那么<s:hidden name="operatorId" required="operatorId">  只要有一个required就可以了,如果加了values就不行了,直接只是有required就ok了。

 

============================================SSH异常========================================= 

Spring

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

  异常描述:Hibernate懒加载异常。在session关闭之后去加载了对象。

  解决方法:添加上OSIV。

org.springframework.dao.InvalidDataAccessApiUsageException: The given object has a null identifier: com.qj.example.model.Energy; nested exception is org.hibernate.TransientObjectException: The given object has a null identifier: com.qj.example.model.Energy

异常描述:这个异常产生的主要原因是DAO采用了Spring容器的事务管理策略,如果操作方法的名称和事务策略中指定的被管理的名称不能够匹配上,spring 就会采取默认的事务管理策略(PROPAGATION_REQUIRED,read only).如果是插入和修改操作,就不被允许的,所以包这个异常。原因是我操作的是游离态的对象,根本就没有获得本省的对象,要load、原来的,才能修改。要更更新的主键还没有传过去。没有找到要更改的用户信息。

 

Hibernate

 No row with the given identifier exists:
  解决方法:

             1) 如果是load方法,你改成get吧。
             2) 多对一要返回null值,可以设置属性not-found="ignore"。

 Remember that ordinal parameters are 1-based!
 问题描述:
             1) hql语句里不需要参数,却添加了一个参数,删掉添加参数的语句就可以了!
             2) 拼串的时候,可变参数要加上,param.toArray();

 org.hibernate.MappingException: Association references unmapped class: com.jshou.user.bean.RelationU2F
  问题描述:hbm.xml映射文件没有添加到hibernate-config.xml中。处理方法:检查映射文件是否已经加载。

 java.lang.IllegalArgumentException: id to load is required for loading
问题描述:没有获取到用于反射的id值。相同类的不同对象写错了。

org.hibernate.PropertyValueException: not-null property references a null or transient value: com.qj.example.model.Energy.name
异常描述:原来始终是有一个值是获得不了的,就是Double让我写成了double
解决方法:在action中必须要写成所有的都是类 如果有double或者是int的就不行了。

 Invalid property 'energyQuery' of bean class [com.qj.example.service.impl.energyManagementServiceimpl]: Bean property 'energyQuery' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
 异常描述:沒有set和get方法。

 Caused by: org.hibernate.hql.ast.QuerySyntaxException: energy is not mapped [select count(*) from com.qj.example.model.RelationUserMeter rum, energy e,operators o where rum.operatorId=e.operatorId and e.operatorId=o.operatorId]

 异常描述:沒有用到类 而是用的是表。

 Exception in thread "main" java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
 异常描述:hql语句里不需要参数,删掉添加参数的语句就可以了。

 Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException;Lantlr/collections/impl/BitSet;)

  异常描述:在进行多条件查询的时候出的错。有可能含有空值。原来写的and之前少写了个空格。

  Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException: Expected positional parameter count: 1, actual parameters: [] [select count(*) from RelationUserMeter rum, Energy en,Operators o where rum.operatorId=en.operatorId and en.operatorId=o.operatorId and en.cashLeft<=?]; nested exception is org.hibernate.QueryException: Expected positional parameter count: 1, actual parameters: [] [select count(*) from RelationUserMeter rum, Energy en,Operators o where rum.operatorId=en.operatorId and en.operatorId=o.operatorId and en.cashLeft<=?]
  解决方法:有一个参数需要指定。

  Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
  解决方法:批量更新实际为0  应该为一  是因为写的Object[]对象与数据的传递不是一样的

  energy is not mapped [select o.operatorId,o.name,e.name,e.energyLeft,e.cashLeft from energy e,operators o where o.operatorId=e.operatorId and e.operatorId=?]

 异常描述:找不到,对应的map  那么就是表没有换成对象。

 

Struts

Dispatcher initialization failed. Unable to load configuration. - [unknown location]
Cannot locate the chosen ObjectFactory implementation: spring - [unknown location]

异常描述:项目只导了strut2的包,但是在配置文件中添加了对spring的配置。

解决方法:删掉配置即可。

Conversion registration error. java.lang.ClassNotFoundException

 异常描述:struts2的拦截器。找不到注册的类。局部注册和全局的注册。有时候写的注册的时候空格也会影响它会找不到。所需要的类。

 There is no Action mapped for namespace /mng/user and action name list. - [unknown location]
 异常描述:这是sturts2中常见的问题,错误原因在于struts2框架接受到一个请求的时候,它会去掉Host, Application和后缀等信息,得到Action的名字,例如如下的请求将得到Welcome这个Action。 http://www.planetstruts.org/struts2-mailreader/Welcome.action
 解决方法:在定义Action的名字的时候不要使用.和/,最好使用英文字母和下划线。

 继上: java.lang.NoSuchMethodException: com.qj.example.action.energyManagementAction.getPersonEngry()

 异常描述:struts2的action中写的方法有参数。

点击页面的按钮跳转之后会调用两个action中的方法,但是直接在地址栏中写上参数又不会报错。
 异常描述:在"submit"的按钮中通过onclick添加了跳转路径,同时又在form的action中添加了跳转。

 解决方法:直接删掉一个就可以了。

Error setting expression 'loc' with value '[Ljava.lang.String;@1a220d7' ognl.MethodFailedException:
  异常描述:转换器的属性文件放错地方了。应该与action同包,并且名字为MyAction-conversion.properties,文件里面添加:
   add(要转换的属性名)=转换器的全限定名。

No result defined for action com.zy.web.action.UserAction and result succ
 异常描述: 自定义struts2的类型转换器时出现异常。 可能与方法名execute()有关系,参考http://blog.sina.com.cn/s/blog_5970f2340100k09e.html

 解决方法:不是用自动加载的,在struts.xml中添加 <constant name="struts.convention.package.locators.disable" value="true"/>

 java.lang.NoSuchMethodException: com.jshou.calendar.web.action.CalendarAction.3st()
异常描述:Action配置的映射有问题。

 No result defined for action com.jshou.calendar.web.action.CalendarAction and result input
 异常描述:Action类下方法中的代码出错时,找不到配置文件的input内容。错误的原因在于页面往action中传递了一个非正确格式的date类型的日期。

 解决方法:添加上即可。

Cannot find class [ com.qj.example.service.impl.energyManagementServiceimpl] for bean with name 'energyManagementService' defined in class path resource [beans_energy_service.xml]; nested exception is java.lang.ClassNotFoundException:  com.qj.example.service.impl.energyManagementServiceimpl

异常描述:因为多了一个空格。

 

 

============================================Server异常========================================= 

Error starting endpoint
 java.net.BindException: Address already in use: JVM_Bind <null>:8080
 原因:8080端口被占用

 异常描述:

               1) 独立运行的Tomcat没有关闭.自安装的tomcat程序设置开机自动运行,或者在之前运行过,先关闭myecplipse或jbuilder,在任务管理器中找到Tomcat的进程,将其kill掉,即可.有时候Tomcat非法关闭时,在进程中,仍然存在,仍然占用8080端口.所以只要将其进程杀掉.就可以解决.

              2) 安装了其他的软件占用了Tomcat的端口.用可以查看端口的工具查看一下,或者,直接改掉tomcat的默认端口即

java.lang.OutOfMemoryError: Java heap space
    Exception in thread "org.springframework.scheduling.quartz.SchedulerFactoryBea
    0_QuartzSchedulerThread" java.lang.OutOfMemoryError: Java heap space
 异常描述:JVM默认分配的内存不够,需要修改配置文件。

 【metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\t does not exist or is not a readable directory 】

  异常描述:WEB项目作了不恰当的重命名相关文件夹,或则误删除某些目录又重新创建后导致eclipse无法在使用热部署时候自动同步相关配置。

 class not found [括号中的是找不到的类] D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\energy\WEB-INF\classes\struts.xml

解决方法:是将D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina路径下???

 

 

 ============================================数据库异常========================================= 

mysql中mysql&#39; 不是内部或外部命令,也不是可运行的程序
  异常描述:命令行中,输入了未知命令会报这个错

  解决方法:应该是在我的电脑上右键-〉属性-〉高级-〉环境变量-〉新建:变量名:path 变量值:mysql.exe所在的bin目录。\bin;

 

 部分参考自:http://student.youkuaiyun.com/space.php?uid=40568&do=blog&id=33336

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值