NoSuchMethodError exception when using com.google.common.base.Splitter

前端 未结 7 2029
一个人的身影
一个人的身影 2021-01-17 07:38

I\'m trying to use com.google.common.base.Splitter as follows

Iterable segs = Splitter.on(\"/\").split(\"one/two/three/four/five\");

for (Stri         


        
相关标签:
7条回答
  • 2021-01-17 08:17

    I encountered the same problem. It turned out that I used a older version of guava. Go to this website:https://code.google.com/p/guava-libraries/, and download a newer version.

    By the way,google-collections was renamed to Guava.

    0 讨论(0)
  • 2021-01-17 08:17

    There are 2 versions: 1) com.google.guava:guava:26.0-android 2) com.google.guava:guava:26.0-jre . Most likely, you assign wrong version as in my case

    0 讨论(0)
  • 2021-01-17 08:22

    Use the below dependency to fix the issue

    To add a dependency on Guava using Maven, use the following:

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

    To add a dependency using Gradle:

    dependencies {
      compile 'com.google.guava:guava:19.0'
    }
    
    0 讨论(0)
  • 2021-01-17 08:25

    Your problem is that another library might also contain a guava library and it's being loaded first from your classpath instead of the version you want. This would cause this runtime exception.

    0 讨论(0)
  • 2021-01-17 08:26

    For me this happens when you have a dependency which depends on an earlier version of Guava, and this dependency is listed first. Guava will be resolved at the place it was found first and ignore the rest.

    The fix is to add the dependency on guava first, but careful that it does not break other projects which use guava

    0 讨论(0)
  • 2021-01-17 08:26

    Yeah, It's the problem with guava library only. Keep the updated library and remove all remaining versions of guava if you have any and try. Should work fine.

    0 讨论(0)
提交回复
热议问题