Chazmondo
Chazmondo

Reputation: 37

NoSuchMethodError: com.google.common.cache.CacheBuilder.maximumSize(J)

I seem to be having a problem which only applied to 1 fellow user of a minecraft plugin of mine.

[15:54:14 ERROR]: Error occurred while enabling <Plugin> v1.0.8 (Is it up to date?) java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.maximumSize(J)Lcom/google/common/cache/CacheBuilder;

Is there any reason as to why this is happening or if I can over come it some way?

My code:

private LoadingCache<String, String> profileCache = CacheBuilder.newBuilder().
        maximumSize(500).
        expireAfterWrite(4, TimeUnit.HOURS).
        build(new CacheLoader<String, String>() {
            public String load(String name) {
                try {
                    return getProfileJson(name);
                } catch (IOException e) {
                    Bukkit.getLogger().info("Error, " + e.getLocalizedMessage() + ".");
                }
                return null;
            }
        });

Upvotes: 2

Views: 6379

Answers (2)

Dennis van der Veeke
Dennis van der Veeke

Reputation: 854

You need to include the libraries into the exported jar. By default they are not included in the exported Jar as the IDE assumes they are present at runtime, which they are not.

See here for Gradle and here for Maven.

Upvotes: 1

Louis Bono
Louis Bono

Reputation: 178

java.lang.NoSuchMethodError is thrown at runtime because the JVM does not find the method in the referenced class. This typically happens because you are using different versions of a third party library for compiling and running the application.

Check the version of the library used for compiling and the version used for running the code and make sure they match or are at least compatible.

Upvotes: 0

Related Questions