我正在关注提到的教程 - http://code.google.com/p/snakeyaml/wiki/Documentation#Tutorial
我的代码看起来像
public class Utilities {
private static final String YAML_PATH = "/problems/src/main/resources/input.yaml";
public static Map<String, Object> getMapFromYaml() {
Yaml yaml = new Yaml();
Map<String, Object> map = (Map<String, Object>) yaml.load(YAML_PATH);
System.out.println(map);
return map;
}
public static void main(String args[]) {
getMapFromYaml();
}
}
我的YAML
文件看起来像
sorting
01: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
当我运行我的程序时,我看到
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at com.ds.utilities.Utilities.getMapFromYaml(Utilities.java:19)
at com.ds.utilities.Utilities.main(Utilities.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Process finished with exit code 1
我该如何解决这个问题以使其正常工作?