繁体   English   中英

线程“main”中的异常 java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;

[英]Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;

我在谷歌中使用闭包编译器。 我是这方面的初学者。 当我运行我的代码时,出现错误。
我想知道是什么原因,或者有没有用过demo。

我的代码:

public class JsClosureCompiler {
    public static String compileJs(String code){

        Compiler compiler = new Compiler();

        CompilerOptions options = new CompilerOptions();
        // Simple mode is used here, but additional options could be set, too.
        CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

        // To get the complete set of externs, the logic in
        // CompilerRunner.getDefaultExterns() should be used here.
        SourceFile extern = SourceFile.fromCode("externs.js",
                "function textDiv(text){};");

        // The dummy input name "input.js" is used here so that any warnings or
        // errors will cite line numbers in terms of input.js.
        SourceFile input = SourceFile.fromCode("input.js", code);

        // compile() returns a Result, but it is not needed here.
        compiler.compile(extern, input, options);

        // The compiler is responsible for generating the compiled code; it is not
        // accessible via the Result.
        if(compiler.getErrorCount() > 0){
            StringBuilder erroInfo = new StringBuilder();
            for(JSError jsError: compiler.getErrors()) {
                erroInfo.append(jsError.toString());
            }
        }
        return compiler.toSource();
    }

    public static void main(String[] args) {
        String code = "function makeNoteDom(noteTitle, noteContent, noteContainer) {\n" +
                "  // Create DOM structure to represent the note.\n" +
                "  var headerElement = textDiv(noteTitle);\n" +
                "  var contentElement = textDiv(noteContent);\n" +
                "\n" +
                "  var newNote = document.createElement('div');\n" +
                "  newNote.appendChild(headerElement);\n" +
                "  newNote.appendChild(contentElement);\n" +
                "\n" +
                "  // Add the note's DOM structure to the document.\n" +
                "  noteContainer.appendChild(newNote);\n" +
                "}\n" +
                "\n" +
                "/**\n" +
                " * Iterates over a list of note data objects and creates a DOM\n" +
                " */\n" +
                "function makeNotes(data, noteContainer) {\n" +
                "  for (var i = 0; i < data.length; i++) {\n" +
                "    makeNoteDom(data[i].title, data[i].content, noteContainer);\n" +
                "  }\n" +
                "}\n" +
                "\n" +
                "function main() {\n" +
                "  var noteData = [\n" +
                "      {title: 'Note 1', content: 'Content of Note 1'},\n" +
                "      {title: 'Note 2', content: 'Content of Note 2'}];\n" +
                "  var noteListElement = document.getElementById('notes');\n" +
                "  makeNotes(noteData, noteListElement);\n" +
                "}\n" +
                "\n" +
                "main();";
        String s = compileJs(code);
        System.out.println(s);
    }
}

------------------------------错误---错误------------ ------------------

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;
    at com.google.javascript.jscomp.deps.DependencyInfo$Require.asSymbolList(DependencyInfo.java:60)
    at com.google.javascript.jscomp.deps.DependencyInfo$Base.getRequiredSymbols(DependencyInfo.java:163)
    at com.google.javascript.jscomp.Compiler.findModulesFromInput(Compiler.java:1901)
    at com.google.javascript.jscomp.Compiler.findModulesFromEntryPoints(Compiler.java:1857)
    at com.google.javascript.jscomp.Compiler.parseInputs(Compiler.java:1666)
    at com.google.javascript.jscomp.Compiler.parseForCompilationInternal(Compiler.java:939)
    at com.google.javascript.jscomp.Compiler.lambda$parseForCompilation$4(Compiler.java:922)
    at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:102)
    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

将番石榴放入 pom.xml

<dependency>
   <groupId>com.google.guava</groupId>
   <artifactId>guava</artifactId>
   <version>22.0</version>
</dependency>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM