com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节的 UTF-8 序列的字节 1 无效。

java.lang.ExceptionInInitializerError
at com.xxc.dao.UserDaoTest.test(UserDaoTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner 2. e v a l u a t e ( P a r e n t R u n n e r . j a v a : 268 ) a t o r g . j u n i t . r u n n e r s . P a r e n t R u n n e r . r u n ( P a r e n t R u n n e r . j a v a : 363 ) a t o r g . j u n i t . r u n n e r . J U n i t C o r e . r u n ( J U n i t C o r e . j a v a : 137 ) a t c o m . i n t e l l i j . j u n i t 4. J U n i t 4 I d e a T e s t R u n n e r . s t a r t R u n n e r W i t h A r g s ( J U n i t 4 I d e a T e s t R u n n e r . j a v a : 68 ) a t c o m . i n t e l l i j . r t . j u n i t . I d e a T e s t R u n n e r 2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.junit.IdeaTestRunner 2.evaluate(ParentRunner.java:268)atorg.junit.runners.ParentRunner.run(ParentRunner.java:363)atorg.junit.runner.JUnitCore.run(JUnitCore.java:137)atcom.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)atcom.intellij.rt.junit.IdeaTestRunnerRepeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: org.apache.ibatis.exceptions.PersistenceException:
Error building SqlSession.
Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节的 UTF-8 序列的字节 1 无效。
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
at com.xxc.utils.MyBatisUtils.(MyBatisUtils.java:23)
… 23 more

遇到这个问题看看xml配置文件中有没有中文。在配置文件中引入了<?xml version="1.0" encoding="UTF-8"?>, 在配置文件可能包含有中文注释,导致在编译后中文注释在配置文件乱码抛异常。我的mybatis-config.xml中有中文注释,将其删掉,即可正常。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 这是一个错误信息,意思是“com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节UTF-8 序列字节 1 无效”。这个错误通常是由于输入的数据不符合 UTF-8 编码规范导致的。 ### 回答2: com.sun.org.apache.xerces.internal.impl.io.malformedbytesequenceexception这个错误信息是Java中XML解析器Xerces报出的异常,提示在解析XML时发生了不合法的字节序列。具体地说,这个异常表示一个包含无效字节序列UTF-8编码的字节数组(byte array)被尝试转换为字符串(String)时出错。 在UTF-8编码中,一个字符可能由1~4个字节组成,而字节的第一个比特位用于指示该字节字节数。如果第一个比特位不是0,那么这说明该字节不是一个字符的开始字节,也就是无效字节序列。异常信息中指出,错误的字节序列包含一个字节,也就是说,在该字节之后没有接着足够的字节来表示一个合法的字符。 这个异常通常是由于不正确的字符编码设置或者存在非法字符导致的。解决这个异常的方法包括: 1.检查XML文档是否使用了正确的编码方式,例如UTF-8、UTF-16等。 2.检查XML文档是否存在不可打印的字符(如控制字符或删除字符等)。 3.在处理XML文档之前,可以使用Java的CharsetDecoder类对字节序列进行解码,或者使用String构造方法指定字符集(Charset)来避免这个异常。 4.如果还是无法解决问题,可以尝试使用其他的XML解析器,例如JDOM、DOM4J等,以找出问题的具体原因。 ### 回答3: 这个错误信息指的是在解析 utf-8 编码的文本时,发现其中包含的一个 1 字节utf-8 序列的第一个字节无效的。在 utf-8 编码中,一个字符可能由多个字节组成,而且每个字节的第一个位都是 1,其他位则表示该字符的二进制编码。因此如果一个 utf-8 序列的第一个字节不符合该规则,则会被判定为无效的。 这种错误一般是由于文本本身的编码格式有误或者被不正确地转换了编码格式,导致其中包含了无效utf-8 序列。解决这个问题的方法通常有三个: 1. 检查文本编码格式:首先需要确保文本的编码格式正确,如果不正确则需要将其转换为正确的编码格式。查看文本的编码格式最简单的方法是打开文本文件,在其中运行一个文本编辑器,然后在查看菜单中查找编码格式选项。 2. 检查文本内容:如果文本的编码格式正确,则需要检查其中是否包含无效utf-8 序列。可以使用一些专门的工具进行检查,例如 UnicodeChecker 等。 3. 给代码增加异常处理:另外,对于代码中可能出现的这种异常情况,也可以增加异常处理代码,当程序在解析 utf-8 编码时遇到无效序列时,会抛出该异常,程序可以捕获该异常并进行相应的处理,比如输出错误信息或者进行其他的操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

傻啦猫@_@

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值