使用guava-23.6-jre.jar出现NoSuchMethodError报错求助
NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList() in Guava 23.6-jre Let's break down what's happening here and walk through fixes tailored to your non-Maven (no pom.xml) IntelliJ project.
This error is almost always caused by Guava version conflict on your classpath. The ImmutableList.toImmutableList() static collector method was added in Guava 21.0. Even though you're using 23.6-jre, there’s likely an older Guava version (20.0 or earlier) being loaded first by the JVM—this old version lacks the method, which is why your setProperty() call on line 39 is failing.
Here’s how to resolve this step-by-step in IntelliJ:
Check for duplicate Guava libraries
OpenFile > Project Structure(use the shortcut Ctrl+Alt+Shift+S to jump there fast). Switch to theLibrariestab, search for "guava", and look for multiple versions listed. If you spot an older release (like 19.0 or 20.0), select it and click the-button to remove it.Verify Guava 23.6-jre is properly configured
If 23.6-jre isn’t in the Libraries list, click the+button, selectJava, then navigate to your localguava-23.6-jre.jarfile and add it. Next, go to theModulestab, select your project module, switch to theDependenciestab, and confirm Guava 23.6-jre is listed with no other Guava versions present.Clean and rebuild your project
Head to the toolbar, clickBuild > Clean Project, thenBuild > Rebuild Project. Stale compiled classes can sometimes cause unexpected issues, so this clears them out. Restart IntelliJ afterward to ensure all changes take effect.Double-check your run configuration’s classpath
Click the run/debug dropdown in the toolbar and selectEdit Configurations. Pick your target run config, go to theClasspathtab, and scan for any old Guava jars. Remove them if found—onlyguava-23.6-jre.jarshould be present here.
One extra note: If your project uses third-party libraries, some might bundle an older Guava version. In that case, drag Guava 23.6-jre to the top of the dependencies list in the Modules > Dependencies tab—this tells the JVM to load your preferred version first.
内容的提问来源于stack exchange,提问作者Nick Slavsky

