GVKun编程网logo

org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1

14

在这里,我们将给大家分享关于org.yaml.snakeyaml.error.YAMLException:java.nio.charset.MalformedInputException:Inputl

在这里,我们将给大家分享关于org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1的知识,同时也会涉及到如何更有效地"xception in thread "main" java.lang.NumberFormatException: For input string: "20、Caused by: java.nio.charset.MalformedInputException: Input length = 1、Caused by: java.nio.charset.MalformedInputException: Input length = 2、com.xfltr.hapax.parser.TemplateParserException: Unexpected or malformed input的内容。

本文目录一览:

org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1

org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1

org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1

 

项目启动报错
2018-12-21 14:06:24.917 INFO 23472 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@561868a0: startup date [Fri Dec 21 14:06:24 CST 2018]; root of context hierarchy
2018-12-21 14:06:25.218 INFO 23472 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 ''javax.inject.Inject'' annotation found and supported for autowiring
2018-12-21 14:06:25.276 INFO 23472 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ''configurationPropertiesRebinderAutoConfiguration'' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$86f6a67d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-21 14:06:25.869 ERROR 23472 --- [ main] o.s.boot.SpringApplication : Application run failed

java.lang.IllegalStateException: Failed to load property source from location ''classpath:/application.yml''
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:549) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:500) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:468) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:450) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_171]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:449) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_171]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:446) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:336) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:215) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:198) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:185) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:171) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:361) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at com.cloud.rest.RestApplication.main(RestApplication.java:14) [classes/:na]
Caused by: org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:254) ~[snakeyaml-1.19.jar:na]
at org.yaml.snakeyaml.reader.StreamReader.<init>(StreamReader.java:58) ~[snakeyaml-1.19.jar:na]
at org.yaml.snakeyaml.Yaml.loadAll(Yaml.java:537) ~[snakeyaml-1.19.jar:na]
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:166) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:139) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:75) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:50) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:567) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:523) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
... 23 common frames omitted
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:281) ~[na:1.8.0_171]
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339) ~[na:1.8.0_171]
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) ~[na:1.8.0_171]
at java.io.InputStreamReader.read(InputStreamReader.java:184) ~[na:1.8.0_171]
at org.yaml.snakeyaml.reader.UnicodeReader.read(UnicodeReader.java:125) ~[snakeyaml-1.19.jar:na]
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:223) ~[snakeyaml-1.19.jar:na]
... 31 common frames omitted

Disconnected from the target VM, address: ''127.0.0.1:52393'', transport: ''socket''

Process finished with exit code 1

 

 

发现是yml内的中文注解,估计是编码原因,将所有的中文注解删除后项目正常启动。

"xception in thread "main" java.lang.NumberFormatException: For input string: "20

spark.SparkContext: Registered listener com.cloudera.spark.lineage.ClouderaNavigatorListener
"xception in thread "main" java.lang.NumberFormatException: For input string: "20
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:492)
    at java.lang.Integer.valueOf(Integer.java:582)
    at com.xiaodao.spark.examples.ml.AdaoKMeanService.main(AdaoKMeanService.java:166)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:730)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
17/10/12 17:42:02 INFO spark.SparkContext: Invoking stop() from shutdown hook
17/10/12 17:42:02 INFO ui.SparkUI: Stopped Spark web UI at http://192.168.1.30:4041
17/10/12 17:42:02 INFO spark.MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
17/10/12 17:42:02 INFO storage.MemoryStore: MemoryStore cleared
 

Caused by: java.nio.charset.MalformedInputException: Input length = 1

Caused by: java.nio.charset.MalformedInputException: Input length = 1

java.lang.IllegalStateException: Failed to load property source from location ''classpath:/application.yml''
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:476)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:465)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:386)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:225)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:195)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:182)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:168)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at com.chinanums.schoolspayment.SchoolspaymentApplication.main(SchoolspaymentApplication.java:10)
    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.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
    at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:254)
    at org.yaml.snakeyaml.reader.StreamReader.<init>(StreamReader.java:58)
    at org.yaml.snakeyaml.Yaml.loadAll(Yaml.java:518)
    at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:157)
    at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:135)
    at org.springframework.boot.env.YamlPropertySourceLoader$Processor.process(YamlPropertySourceLoader.java:101)
    at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:58)
    at org.springframework.boot.env.PropertySourcesLoader.load(PropertySourcesLoader.java:128)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.doLoadIntoGroup(ConfigFileApplicationListener.java:490)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:473)
    ... 22 common frames omitted
Caused by: java.nio.charset.MalformedInputException: Input length = 1
    at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at org.yaml.snakeyaml.reader.UnicodeReader.read(UnicodeReader.java:125)
    at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:223)
    ... 31 common frames omitted

第一种可能是你的application.yml文件编码格式有问题,改为UTF-8,如下:

 

 第二种:

可能就是你的application.yml文件是通过把其他类型的文件后缀名直接改为yml生成的,这时就需要你把application.yml中的内容全部复制,然后删除,再新建一个application.yml文件,

将复制的内容拷贝进去再运行项目就不会报错了。

Caused by: java.nio.charset.MalformedInputException: Input length = 2

Caused by: java.nio.charset.MalformedInputException: Input length = 2

java.nio.charset.MalformedInputException: Input length = 2 异常表示输入数据的长度不正确,导致字符集解析失败。

MalformedInputException 是 Java NIO(New I/O)中的一个异常类,它通常在字符集编解码时出现问题时抛出。在你的情况下,输入数据的长度为2,可能与所使用的字符集或编码方式不匹配。

要解决这个异常,你可以考虑以下几个方面:

  1. 确认输入数据的编码方式:检查你的代码中用于读取输入数据的部分,并确认所使用的字符集是否正确。如果你知道输入数据的编码方式,可以使用相应的字符集进行解码。

    例如,如果输入数据的编码为 UTF-8,你可以使用以下方式进行解码:

Charset charset = StandardCharsets.UTF_8;
String decodedString = new String(inputBytes, charset);

 

  1. 如果不确定输入数据的编码方式,可以尝试使用不同的字符集进行解码,观察是否能够成功解析数据。

  2. 处理输入数据长度不正确的情况:如果输入数据的长度确实不正确,你可能需要检查数据源或数据传输过程中是否存在问题。确保输入数据的长度和内容与预期一致,以避免解码时出现异常。

    另外,还可以尝试使用更为健壮的解码方式,如使用 CharsetDecoder 类进行逐个字符的解码,从而更灵活地处理输入数据的异常情况。

 

    public static void main(String[] args) {
        byte[] inputBytes = new byte[] { 1, 2, 3, 4, 5 };

        Charset charset = StandardCharsets.UTF_8;
        ByteBuffer inputBuffer = ByteBuffer.wrap(inputBytes);
        CharBuffer outputBuffer = CharBuffer.allocate(inputBytes.length);
        CharsetDecoder decoder = charset.newDecoder();
        decoder.onMalformedInput(CodingErrorAction.IGNORE); // 忽略输入长度不正确的情况
        decoder.decode(inputBuffer, outputBuffer, true);
        decoder.flush(outputBuffer);
        outputBuffer.flip();
        String decodedString = outputBuffer.toString();
        System.out.println("decodedString = " + decodedString);
    }

 

  1. 考虑数据源的可靠性:如果你的输入数据来自外部源(如网络、文件、数据库等),确保源数据的完整性和正确性。在一些情况下,输入数据的损坏或错误可能导致解码异常。

    可以使用校验和或其他方法验证输入数据的完整性,并确保数据的准确性和一致性。

根据具体情况选择适当的字符集和解码方式,确保输入数据的正确解析。

 

com.xfltr.hapax.parser.TemplateParserException: Unexpected or malformed input

com.xfltr.hapax.parser.TemplateParserException: Unexpected or malformed input

为什么我调用接口的时候会报这个错误呢,我检查了传入的值是没有问题的啊

 

关于org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于"xception in thread "main" java.lang.NumberFormatException: For input string: "20、Caused by: java.nio.charset.MalformedInputException: Input length = 1、Caused by: java.nio.charset.MalformedInputException: Input length = 2、com.xfltr.hapax.parser.TemplateParserException: Unexpected or malformed input等相关内容,可以在本站寻找。

本文标签: