上海大 小企业网站制作搜索引擎推广有哪些
重拾者: 每日记录至目前(记录51种不同场景的问题可参考解决方案)
异常就两部分:
1、excepiton信息: 报错产生的原因
2、at开头表示: 异常产生的代码位置。欢迎关注本人微信公众号:AIMING2020
拆分两篇博客
(第一部分1-36)地址如下:JAVA 经常遇到一些问题【第一部分1~35】
(第一部分37-51)地址如下:JAVA 经常遇到一些问题【第二部分36~51】
问题1:Maven 项目中Cannot find declaration to go to或者运行报Java:程序 X.XXX 不存在
问题2:修改maven 本地仓库和远程仓库
问题3:No archetype found in remote catalog. Defaulting to internal catalog
问题4:Package 'junit:junit' can be upgraded to version '4.13.2'
问题5:Dependency 'org.seleniumhq.selenium:selenium-java:4.0.0' not found
问题6:Exception in thread "main" java.lang.NullPointerException(空指针异常)
问题7:'Throwable' argument 'e.fillInStackTrace()' to 'System.out.println()' call
问题8:Result of 'random.nextInt(target.length - 1)' is always '0'
问题9:报错 Not a statement(不是声明)
问题10:新增java文件添加自动注释模版
问题11:为方法添加自动注释模版
问题12:Map 与HashMap 方法的用法以及结合replaceAll使用
问题13:①同一个类中文件调用方法,②不同类中调用方法
问题14:Collection 'paramMap.keySet()' is always empty
问题15:Exception in thread "main" java.lang.NoSuchFieldError: XXX
问题16:The method XXX cannot be declared static; static methods can only be declared in a static or top level type
问题17:Unhandled exception type NoSuchProviderException
问题18:Mavan、Testng、junt ①Maven 设置自定义仓库本地仓库
问题19: 'XXX' is abstract; cannot be instantiated
问题20:Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument 使用js 点击输入图片
问题21:email 发送问题归纳
疑问①:Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
疑问②:javax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.com, port: 587; nested exception is:javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
疑问③:javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
疑问④:Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 587;
疑问⑤:javax.mail.AuthenticationFailedException
疑问⑥:com.sun.mail.smtp.SMTPSendFailedException: 503 Error: need EHLO and AUTH first !
疑问⑦:javax.mail.AuthenticationFailedException: failed to connect, no password specified?
疑问⑧: Unhandled exception type NoSuchProviderException
疑问⑨:javax.mail.AuthenticationFailedException: 535 Login fail. Authorization code is expired
问题22:Unhandled exception type NoSuchProviderException
问题23:Log4j2报错并且没有生成log日志文件
问题24:非错误类,byte直接输出十进制,怎么输出二进制??
问题25:非错误类,方法中含byte数组参数如何输入调用??
问题26:com.fasterxml.jackson.core.JsonParseException:
问题27:pom.xml项目管理文件中结构
问题28:Exception in thread "main" com.alibaba.fastjson2.JSONException: unclosed
问题29:java.lang.StringIndexOutOfBoundsException: String index out of range: -1
问题30:ElementNotInteractableException: Element XXXX could not be scrolled into view
问题31:在cmd中运行jar包出现 报错XXX.jar中没有主清单属性 怎么回事呢?
问题32:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: X
问题33:运行jar包时 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
问题34:Connect to 127.0.0.1:8888 [/127.0.0.1] failed: Connection refused: connect
问题35:在postman 可以请求,但在httpcliect发起请求返回响应状态码400
实际目录
问题36:fastjson2.JSONException: offset X, character X, line X, column X
问题37:Cannot resolve symbol 'XXXXXX'
问题38:Exception in thread "main" java.lang.ClassCastException: com.testing.class10.Cat cannot be cast to
问题39:java.lang.IllegalArgumentException: Keys to send should be a not null CharSequence:
问题40:org.yaml.snakeyaml.error.YAMLException: java.io.IOException: Stream closed
问题41:'dependencies.dependency.version' for org.jetbrains:annotations:jar is either LATEST or RELEASE (both of them are being deprecated) @ line 63, column 22
问题42:'Missing management agent resource bundle: key = ""'
问题43:解决Springboot启动报错:类文件具有错误的版本61.0,应为 52.0
启动Springboot项目时候报错
原因
问题44:类文件具有错误的版本 55.0, 应为 52.0
问题45: Exception in thread "main" java.lang.UnsupportedOperationException
问题46: Exception in thread "main" java.lang.UnsupportedOperationException
问题47:调用企业微信响应报错:"errcode":60020
问题48:Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'controller' method
问题49:java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
问题50:java.lang.AbstractMethodError: love.forte.simbot.spring.autoconfigure.SimbotAppPropertiesConfiguration.registerBeanDefinitions
问题51:连接数据库出现错误(windows更新8.XX版本以上)
疑问①:数据库连接配置失败,报错内容: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
疑问②:"main" java.lang.RuntimeException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
疑问③:java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
疑问④:java.lang.IllegalArgumentException: Property 'dataSource' is required
问题36:fastjson2.JSONException: offset X, character X, line X, column X
fastjson2.JSONException: offset X, character X, line X, column X
fastjson2.JSONException 中的异常:偏移量 X,字符 X,第 X 行,第 X 列
String jq="{\"Srcid\":\"5809\"}";
JSONObject json = JSON.parseObject(jq);
JSONArray data = json.getJSONArray("Srcid");
已经是标准json格式但是仍报错
原因:无法重组成为一个数组格式json的数组格式
JSONArray data = json.getJSONArray("XXX");
数组格式为:{"X1","X2","X3"};
详情-请参考:Java 基础知识--重拾者AIMING_Aimin20210819的博客-CSDN博客
修改为如下 :
String jq="{\"Srcid\":[{\"age\":\"5809\",\"word\":\"hello\"}]}";
JSONObject json = JSON.parseObject(jq);
JSONArray data = json.getJSONArray("Srcid");
问题37:Cannot resolve symbol 'XXXXXX'
Cannot resolve symbol 'XXXXXX' 翻译:无法解析符号“XXXXXX”
解决办法1:先检查pom文件依赖是否报错,报错需重新导入
解决办法2:重启IDEA,清理缓存
解决办法3:删除.idea,然后重启idea
解决办法4:检查jdk版本是否与导入项目的版本一致 【Ctrl+shift+alt+s】打开
问题38:Exception in thread "main" java.lang.ClassCastException: com.testing.class10.Cat cannot be cast to
类型转换的错误,不能将原本是其它子类类型的父类对象转成另一个子类类型。
编译器不会报错,执行的时候才会。
问题39:java.lang.IllegalArgumentException: Keys to send should be a not null CharSequence:
java.lang.IllegalArgumentException: Keys to send should be a not null CharSequence:
IllegalArgumentException:要发送的键应该是非空字符序列:
问题40:org.yaml.snakeyaml.error.YAMLException: java.io.IOException: Stream closed
Exception in thread “main” java.io.IOException: Stream Closed
流被关闭了。
问题41:'dependencies.dependency.version' for org.jetbrains:annotations:jar is either LATEST or RELEASE (both of them are being deprecated) @ line 63, column 22
原因:这个原因是因为父pom中定义了子pom中的版本,
当删除 父pom中的内容时,就会导致子pom所在的工程执行mvn出现上述版本消失的报错。
此处是重复声明,在pom.xm 删除一个就可以
问题42:'Missing management agent resource bundle: key = ""'
原因如下
解决方案:删除getText方法
public static void assertDbExist(String headSql, String conditionSQL, String tailSql){String lastSQL = headSql + conditionSQL + tailSql;log.info("执行的sql语句:" + lastSQL);createCon("jdbc:mysql://localhost:3306/abs_task?useSSL=false&useUnicode=true&characterEncoding=utf-8allowMultiQueries=true", "root", "123456");if (hasResult(replaceParam(lastSQL))) {log.info("测试成功");} else {log.info("测试失败,sql语句没有查到");}}
问题43:解决Springboot启动报错:类文件具有错误的版本61.0,应为 52.0
目录
- 启动Springboot项目时候报错
- 原因
- 总结:
启动Springboot项目时候报错
java: 无法访问org.springframework.dao.DataAccessException 错误的类文件:/D:/software_apache_mysql/apache-maven-3.9.0/repository/org/springframework/spring-tx/6.0.6/spring-tx-6.0.6.jar!/org/springframework/dao/DataAccessException.class 类文件具有错误的版本 61.0, 应为 52.0;请删除该文件或确保该文件位于正确的类路径子目录中。
请删除该文件或确保该文件位于正确的类路径子目录中。
原因
springframework使用了1.2.16或者1.2.16以上,因为Spring官方发布从Spring6以及SprinBoot3.0开始最低支持JDK17,所以仅需将springframework版本降低为1.2.16以下即可。
将SpringBoot版本降低为3.0以下 版本随意,刷新Maven重启即可
问题44:类文件具有错误的版本 55.0, 应为 52.0
Java版本对应依赖不匹配导致,55应该Java1.11,52是Java1.8,解决办法1.提高或者降低Java运行环境,2.修改依赖版本
Java版本参考:类文件具有错误的版本 55.0, 应为 52.0
问题45: Exception in thread "main" java.lang.UnsupportedOperationException
循环删除空或者null,会报错,翻译:线程“main”java.lang.Unsupported操作异常
解释原因:调用arrays.aslist()之后的list不能对这个list进行add或者remove操作,这是因为这个方法返回的list是内部类list而不是java.utils下的arrayList。
解决方法:再套一层ArrayList,就是重新把转换出的list转成java.utils下的arrayList
原文链接:Exception in thread “main“ java.lang.UnsupportedOperationException_代码先敲住的博客-CSDN博客
问题46: Exception in thread "main" java.lang.UnsupportedOperationException
原因:由于List等Collection的实现并没有同步化,多线程应用程序中出现同时访问,而且出现修改操作的时候都要求外部操作同步化;调用Iterator操作获得的Iterator对象在多线程修改Set的时 候也自动失效,并抛出java.util.ConcurrentModificationException。这种实现机制是fail-fast,对外部的修改并不能提供任何保证。
List、Set等是动态的,可变对象数量的数据结构,但是Iterator则是单向不可变,只能顺序读取,不能逆序操作的数据结构,当 Iterator指向的原始数据发生变化时,Iterator自己就迷失了方向。
解决办法新增,需要再定义一个List,用来保存需要删除的对象:
List delList = new ArrayList();
最后只需要调用集合的removeAll(Collection con)方法就可以了。
问题47:调用企业微信响应报错:"errcode":60020
not allow to access from your ip, hint: [1691732115431492008231797], from ip: XXX.XX.XX.XXX, more info at https://open.work.weixin.qq.com/devtool/query?e=60020
解决办法:后台管理–应用管理–应用–选中你创建的那个应用–开发者接口–企业可信IP
问题48:Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'controller' method
疑问①:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘xx‘ defined in URL
原因: controller层出现了重复的方法映射
解决方案:解决Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘inteController‘_wiser_CC的博客-CSDN博客
//ip+端口@GetMappingpublic String getGDNoHelloWord(){return "hello word";}//ip+端口@ApiOperation(value = "get请求固定URL",notes="get请求描述固定URL")@GetMapping("/{bookName}/{money}")public String getGD(@ApiParam(name="bookName",value = "书名") @RequestParam String bookName, @ApiParam(name="money",value = "多少钱") @RequestParam String money){System.out.println("".equals(money));return "这个是个get方法固定URL,"+ "老板这个书名为"+ bookName + ",你有多少钱?money=="+money+"元";}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘xxx‘ 解决方案:_爱打羽球的码猿的博客-CSDN博客
问题49:java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
解决办法一: spring-test 和 spring-context 版本不一致,保持一致
解决办法二:加载了两个依赖,且版本不同导致IDEA找到
解决:Caused by: java.lang.ClassNotFoundException: org.springframework.core.metrics.ApplicationStartup_bug_Silence丶你的名字-华为云开发者联盟
解决办法三:spring boot版本升级原因:
Spring Boot 3.0 升级小指南_升级springboot版本_@SmartSi的博客-CSDN博客
解决办法四:原因是由于springboot包和spring包冲突了,删除spring包即可
Getting Started | Building a RESTful Web Service
问题50:java.lang.AbstractMethodError: love.forte.simbot.spring.autoconfigure.SimbotAppPropertiesConfiguration.registerBeanDefinitions
暂无解决办法,尚未记录
问题51:连接数据库出现错误(windows更新8.XX版本以上)
疑问①:数据库连接配置失败,报错内容: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Java通过jdbc连不上数据库-编程语言-CSDN问答
IDEA无法链接代理The driver has not received any packets from the server._Aimin2022的博客-CSDN博客
疑问②:"main" java.lang.RuntimeException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
原因:
1.密码端口用户名错误等待
2.依赖文件不对应
解决办法一:
1、检查本地通过navicat是否可以连接,主要验证是否用户和密码及端口是否
2、数据库并没有给你分配足够的权限
alter user root@localhost identified by '123456'
use mysql;
update user set password=password(‘newpwd') where user='root' and host='localhost';
flush privileges;
修改权限
CREATE USER 'root'@'localhost' IDENTIFIED BY '123456';
grant all privileges on *.* to 'root'@'%' with grant option;
数据库基础(库、表、视图、属性、数据类型、约束、索引)增删改查_数据库增删改查关键字是什么_Aimin2022的博客-CSDN博客
3、更新Jdbc 的url是否发生错误
characterEncoding=utf-8
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8&allowPublicKeyRetrieval=true
IDEA 报错: java.sql.SQLException: Access denied for user ‘root ‘@‘localhost‘ (using password: YES)_SHNIXU的博客-CSDN博客
解决办法二:
换成对应依赖即可
疑问③:java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
&allowPublicKeyRetrieval=true 改成如下
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8&allowPublicKeyRetrieval=true
characterEncoding=utf-8
jdbc.user=root
jdbc.password=12345678