Java错误解决方法合集

错误和解决方法都是亲自验证过的,解决方法可以用!不断更新中。

文章目录

一、错误提示:Unexpected exception encountered during query.

java.sql.SQLException: Unexpected exception encountered during query.

解决方法:

更换使用新版的mysql-connector-java即可。

二、错误提示:MYSQL插入中文显示乱码。

MYSQL插入中文显示乱码。
解决方法:

修改my.ini文件的编码为UTF8,步骤如下:

  1. 打开我的电脑,地址栏输入“%ProgramData%”,然后进入“MYSQL”目录,再进入“MySQL Server 8.0”目录即可看到my.ini文件。
  2. 找到如下内容,修改:
    [mysql]
    default-character-set=utf8
    [mysqld]
    character-set-server=utf8
  3. 重启MYSQL即可。

三、错误提示:windows中没有mysql服务。

windows中没有mysql服务。

解决方法:

(注意:计算机右键-管理-服务和应用管理-服务中查看MYSQL服务名称,有些MYSQL服务名是“MYSQL80”)

开始->运行->cmd,进到mysql安装的bin目录

D:\MySQL\bin>mysqld.exe -install

Service successfully installed.

这个时候刷新服务列表mysql就出现了,启动就可以了,或者可以直接在cmd中做如下操作

D:\MySQL\bin>net start mysql

四、错误提示:Client does not support authentication

Client does not support authentication protocol requested by server; consider upgrading MySQL client

解决方法:
在MYSQL中执行如下语句

USE mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '831015';
FLUSH PRIVILEGES;

五、错误提示:Unknown initial character set index ‘255’

Unknown initial character set index ‘255’ received from server. Initial client character set can be forced via the ‘characterEncoding’ property.

解决方法一:
参照如下URL进行修改

String url = "jdbc:mysql://localhost:3306/db_cjky?useUnicode=true&characterEncoding=utf8";

解决方法二:
在url的链接后面增加

?useSSL=false&serverTimezone=Hongkong&useUnicode=true&characterEncoding=utf-8

六、错误提示:C3P0相关:Communications link failure

Communications link failure

解决方法:
参照第五条错误去解决

七、错误提示:C3P0相关:Unknown system variable ‘tx_isolation’

java.sql.SQLException: Unknown system variable ‘tx_isolation’

解决方法:
mysql-connector-java版本太低,更新到高版本即可。

八、错误提示:C3P0相关:The server time zone value ‘???ú±ê×??±??’

The server time zone value ‘???ú±ê×??±??’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

解决方法:
在url后面加上serverTimezone=GMT,如果需要使用gmt+8时区,需要写成GMT%2B8

?useUnicode=true&serverTimezone=GMT%2B8&characterEncoding=utf8

九、错误提示:C3P0相关:WARN: Establishing SSL connection without server’

WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

解决方法:
在mysql连接字符串url中加入ssl=true或者false即可

?useSSL=false

十、错误提示:C3P0使用配置文件就报错,各种错误。

解决方法:
有可能是XML配置文件中的URL书写错误,URL中的“&”需要用“&”表示。

十一、错误提示:eclipse项目显示红色感叹号

eclipse项目显示红色感叹号
解决方法:
由于缺少 jar 包引起的,按照如下流程删掉对应的无效包:

  1. 在有出现红色感叹号项目的文件上点击右键,依次选择Build Path - Configure Build Path
  2. 在弹出的对话框中,左侧选择“Java Build Path”(默认选择),点击右侧“Libraries”,下面会出现对应出错的包
  3. 删掉对应的包即可

十二、错误提示:Eclipse没有Build Path 的解决方法

Eclipse没有Build Path 的解决方法

解决方法:
Window ->show view 选择package explorer

十三、错误提示:Failed to execute goal org.apache.rat:apache-rat-plugin:0.12:check (rat-

[ERROR] Failed to execute goal org.apache.rat:apache-rat-plugin:0.12:check (rat-
check) on project maven-model: Too many files with unapproved license: 1 See RAT
report in: E:\java\maven\app\target\rat.txt -> [Help 1]

解决办法:

在每个新建的类的第一行加入以下内容即可

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

十四、错误提示:Eclipse执行mvn install错误

Eclipse执行mvn install错误

解决办法:
尝试更换jdk版本

十五、错误提示:the resource is not on the build path of a java project

在eclipse使用了Maven,在使用自动生成代码时提示如下错误
the resource is not on the build path of a java project

解决方法一:(推荐)

此问题是因为eclipse在默认的源码存放路径下没有找到对应的java文件导致。可以把对应的java文件移动到对应的目录下。通常java文件需要放在:
src/main/java/

解决方法二:
此问题是因为eclipse在默认的源码存放路径下没有找到对应的java文件导致。可以更改java源码存放位置
右键—>Properties—>Java Build Path 上找到Source选项卡,里面修改源码存放位置即可。

十六、错误提示:Eclipse中JSTL的uri属性无法自动补全。

Eclipse中JSTL的uri属性无法自动补全。

解决方法:

  1. 检查是否有导入jstl包
  2. 如果导了包,在“uri=”处进行alt+/补全。

十七、错误提示:JSTL:Unable to convert string [] to class [java.util.Date] for attribute [value]: [Property Editor not registered with the PropertyEditorManager]

在JSP页面中添加<%@ taglib prefix=“fmt” uri=“http://java.sun.com/jsp/jstl/fmt” %>后就报错。错误提示:

Unable to convert string [] to class [java.util.Date] for attribute [value]: [Property Editor not registered with the PropertyEditorManager]

解决方法:
检查JSP文件中跟jstl相关的代码,不能有语法错误,即便是注释的内容也必须语法正确。把语法错误的代码删掉即可。

十八、Eclipse中@Resource注解时提示错误

Eclipse中@Resource注解时提示错误

解决方法:
手动导入javax.annotation.Resource即可

十九、Eclipse中XML文件没有自动补全

Esclipse中使用自动补全命令不能显示对应的提示。

解决方法:

菜单:Window -> Preferences -> General -> Editors -> File Associations
在右侧点击“add”按钮,添加“.xml”。
然后在下方选择“Associated editors”处选择“XML Editor (default)…”,再点击右侧“Deafult”按钮,确定即可

二十、错误提示:Property Editor not registered with the PropertyEditorManager

从数据库中取出Timestamp格式数值,返回给JSP页面,提示如下错误:

org.apache.jasper.JasperException: Unable to convert string [${dept.create_time }] to class [java.util.Date] for attribute [value]: [Property Editor not registered with the PropertyEditorManager]

解决方法:
在JSP顶部添加:

//指定JSP中的表达式被当成字符串处理
<%@ page isELIgnored="false"%>

二十一、Eclipse无法自动提示类名

Eclipse中无法自动提示类名。

解决方法:

参考资料:https://blog.csdn.net/hh775313602/article/details/70176531

  1. 点击Eclipse菜单‘Help -> About Eclipse’
  2. 点击Eclipse图标,查看版本
  3. 找到“Feature Name”名为“Eclipse Platform”的行,右侧“Version”列就是版本号
  4. 通过在线安装的方式安装。点击Eclipse菜单‘Help ->Install New Software…. ’
  5. 输入如下网址 ,最后的4.3是Eclipse的版本号
    http://dist.springsource.com/release/TOOLS/update/e4.3/
    
  6. 选择需要安装的插件,建议只勾选SpringIDE即可,一共四个
    Core / Spring IDE
    Extensions / Spring IDE
    Integrations / Spring IDE
    Resources / Spring IDE
    
  7. 去掉下方名为“Contact all update sites during install to find required software”选项前面的勾。点击Next。
  8. Eclipse会查找一下,稍等一会,然后继续点击‘Next’即可
  9. 继续点击‘Next’
  10. 选择I accepte the termsof the license agreements,然后点击’Finish’按钮。
  11. 这时候Eclipse会在后台安装,在右下角可以看到安装进度,请耐心等待。
  12. 安装好后,会提示让重启Eclipse,点击确定即可。(如果安装中途出错,多试几次即可)
  13. 到目前为止,输入第一个包名后,按Alt+/就可以弹出类名提示
  14. 如果是XML文件,要修改打开方式:在Ecplise项目中右键xml文件-选择“Open With”-“XML Editor”

二十二、XML没有模板配置

XML没有预设的模板内容,例如mybatis的配置文件模板。

解决方法:

  1. 打开 window–>Preferences–>xml–>xml files–>templates–>new
  2. 在“name”中添加名称,“Description”中添加说明。“Pattern”中添加模板内容,如:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper
    	PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
    <mapper namespace="com.imooc.shop.repository.ArticleTypeMapper">
    
    </mapper>
    
  3. 在mapper.xml文件中,alt+/提示,选择mapper即可出现模板内容

二十三、Eclipse中项目和Java Resource出现红叉

Eclipse中项目和Java Resource出现红叉。

解决方法:

JRE和项目配置的不一致导致。让如下方式修改:

  1. 右键项目名称,选择“Properties”。
  2. 左侧选择“Project Facets”,在右侧“Project Facet”列找到“Java”行,右侧的“Version”列值改为对应的JRE版本。
  3. 点击确定
  4. 选择左侧“Java Build Path”,右侧选择“Libraries”,修改“JRE System Library”中的JRE环境(需要指向本地的JRE路径)
  5. 如果有使用Maven,右键项目,选择“maven”,选择“Update Project”即可
  6. 执行完以上三步后,搞定。

如果执行以上三步还未解决,可以点击顶部菜单Windows-Show View-Other…

然后搜索Problems,打开这个Problems窗口可以看到具体的错误提示。

二十四、错误提示:The prefix “p” for attribute

在XML文件(spring配置文件)中出现如下提示:

The prefix “p” for attribute “p:dataSource-ref” associated with an element type “bean” is not bound.

解决方法:

意思是没有定义前缀p的含义。在xml配置文件中加入如下内容即可:

xmlns:p="http://www.springframework.org/schema/p"

二十五、错误提示:java.io.UnsupportedEncodingException:

提示如下错误,xxxx处为各式各样的内容。

java.io.UnsupportedEncodingException: xxxx

解决方法:

出现这种错误提示,表示传递的解码格式名称有误。xxxx位置填写的应该是正确编码的名称。

二十六、错误提示:A query was run and no Result Maps were found for the Mapped Statement

spring+mybatis。出现如下错误提示:

Caused by: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement ‘com.qqfh.bookshop.repository.BookMapper.getAll’. It’s likely that neither a Result Type nor a Result Map was specified.

解决方法:

意思是有返回结果的查询没有设置返回对象。在有返回结果的查询中中添加如下内容即可:

resultType="Article"

二十七、安装MYSQL没有MYSQL SERVER选择

在32位系统通过MSI安装MYSQL的8以上版本时,没有mysql server安装。只有其他插件安装成功。

解决方法:

MYSQL 8版本只有一个64位的安装包,里面没有mysql server安装。使用mysql 5版本的32位即可。

二十八、Git错误提示:fatal: unable to auto-detect email address

执行“git commit -am ‘first commit init project’”后提示错误:

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'JUNHONG@JUNHONG-PC.(none)')

解决方法:

找到工程目录 (Project)的.git文件夹,打开之后找到config文件,在最后边加上如下内容

[user]
email=your email
name=your name

二十九、Eclipse的servers里没有项目

在Eclipse的Servers添加项目时,没有出现想要添加的项目。

解决方法:

右键项目-properties-选择“Project Facets”-在右边勾选“Dynamic Web Module”和“JavaScript”即可

(如果勾选后没有出现version列,可以确定后重新进入这个界面即可)

可能出现的问题:JSP页面有红叉,请参照三十解决。

三十、Eclipse中JSP页面和项目出现红叉

JSP页面和项目出现红叉。

解决方法:

  1. 右键项目-buildpath-Configure Build Path…
  2. 点击右侧的“Libraries”,点击“Add Library…”
  3. 选择“Server Runtime”,点击"Next"
  4. 选择一个配置好的Tomcat,点击finish即可
  5. 此时红叉消失。

三十一、错误提示:Request processing failed; nested exception is java.lang.NullPointerException

使用spring mabatis时,错误提示内容如下:

严重: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException

解决方法:

service实现类中,mapper的注入错误,使用@Autowired注入即可。

三十二、nginx配置后一直访问主页,显示nginx主页

nginx配置后,访问配置的域名,一直显示nginx的首页。

解决方法:

配置错误,检查配置

  • 比如include指向的文件不存在(vhost文件夹需要在conf目录下)
  • nginx.conf配置文件中有include其他配置,导致冲突

三十三、错误提示:java.util.HashMap cannot be cast to com.qqfh.pojo.Cart

错误提示:

严重: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: java.util.HashMap cannot be cast to com.qqfh.pojo.Cart] with root cause
java.lang.ClassCastException: java.util.HashMap cannot be cast to com.qqfh.pojo.Cart

解决方法:

MyBatis的配置错误,返回结果应该是对象类型,而不是map类型。

三十四、服务器上使用Maven编译时提示编译错误,本地无问题

本地使用Maven编译打包正常,但是项目上传到服务器之后,编译打包提示错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project qqfh: Compilation failure
[ERROR] /developer/git-repository/MALL/src/main/java/com/qqfh/service/impl/CartServiceImpl.java:[7,16] error: cannot find symbol
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

解决方法:
没有配置服务器上的仓库。在Maven目录下的conf/文件下,编辑settings.xml文件,修改如下内容,保存即可:

<mirrors>
  <!-- mirror
   | Specifies a repository mirror site to use instead of a given repository. The repository that
   | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
   | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
   |
  <mirror>
    <id>mirrorId</id>
    <mirrorOf>repositoryId</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://my.repository.com/repo/path</url>
  </mirror>
   -->
   <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>       
  </mirror>
</mirrors>

三十五、错误提示:tmp_count’ at line 12

出现如下错误提示:

### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') tmp_count' at line 12

解决方法
表示SQL语句错误,需要检查SQL语句。tmp_count是pageHelper所加上的内容。

三十六、Eclipse无法自动编译

  1. Eclipse无法自动编译
  2. System.out.println();失效,无法执行
    解决方法\
  3. 点击菜单“Project”-选择“Build Automatically”,开启自动编译
  4. 方法失效可能是因为编译运行失败,所以这条语句没有被增加进去,开启自动编译后,再启动tomcat运行程序试试

三十七、错误提示:Cannot read property ‘properties’ of undefined

如果执行npm run dist命令时出错,提示Cannot read property ‘properties’ of undefined

解决方法:
升级webpack-cli到3.1.1即可,执行命令:

npm i webpack-cli@3.1.1 -D

三十八、错误提示:Please, fix them up in the work tree, and then use 'git add/rm ’

Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

解决方法:

  1. 表示本地文件和远程仓库文件有冲突,如果当前分支一直没有变过,则可以还原本地文件到最近一次git pull,然后再使用git pull获取最新:
    //还原到最近一次成功git pull的记录
    git reset --hard FETCH_HEAD
    
  2. 如果分支发生改变,同时本地的内容可以丢弃,那么执行获取远程制定分支的指定log即可
    git reset --hard origin/v2.0
    
  • 5
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值