Error creating java guava java event

I am trying to use EventBus from Google Guava libraries.

From the Guava documentation, it should be easy to instantiate an EventBus object.

My code is:

package test; import com.google.common.eventbus.EventBus; public class Test { public static void main(String[] args) { EventBus bus = new EventBus("Sample"); } } 

I get this error:

 Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Objects.firstNonNull(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; at com.google.common.cache.CacheBuilder.getKeyStrength(CacheBuilder.java:355) at com.google.common.cache.CustomConcurrentHashMap.<init>(CustomConcurrentHashMap.java:206) at com.google.common.cache.ComputingCache.<init>(ComputingCache.java:39) at com.google.common.cache.CacheBuilder.build(CacheBuilder.java:569) at com.google.common.eventbus.EventBus.<init>(EventBus.java:156) at test.Test.main(Test.java:7) Java Result: 1 

I tried with Guava 10.0, 11.0 and 12.0 and always with the same error. I am on OSX Lion and I am using Netbeans 7.1: I have tried both Java 6 (32 and 64 bit) and Java 7: no improvements. I can't find anything on google. Is this a problem with guava? Or, as usual, am I missing something?

Respectfully,

Alessandro

+6
source share
2 answers

To expand on what @biziclop said, you most likely have the latest version of Guava, either google-collect, or a version of Guava up to 3.0 on your class path. Objects.firstNonNull was added in 3.0, assuming an older version of this class is loading.

+17
source

I had the same problem. I used google-collections 1.0, where guava v11. This problem went away after I upgraded to

<!-- https://mvnrepository.com/artifact/com.google.guava/guava --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>19.0</version> </dependency> by

 <dependency> <groupId>com.google.collections</groupId> <artifactId>google-collections</artifactId> <version>1.0</version> </dependency> 
+2
source

Source: https://habr.com/ru/post/920051/


All Articles