Missing .instance() method (not related to JME)


I got some source code to work on it - a project written in Java which uses LibGDX.

There are several lines of code lke this one:


The problem is that IDE can’t find .instance(). There is no such thing in sources.
I’ve never used Provider before, I don’t need to understand it, touch it or even look at it. Google does not helps this time. I’m sure that something is missing - I have there clean IntelliJ and Java 1.8 u 100-something.

Any hint?

Where is Provider being imported from?

It doesn’t seem to be the one in Java.

1 Like

Just noticed that… they have their own Provider:

public final class Provider {
    private static final Logger logger = LoggerFactory.getLogger(Provider.class);
    private static final Map<Class<?>, ReferenceHolder> holder = new HashMap<Class<?>, ReferenceHolder>();
    private static final Map<String, ReferenceHolder> holderNamed = new HashMap<String, ReferenceHolder>();

public static <T> ReferenceHolder<T> get(Class<T> clazz) {
    return get(clazz, false);

public static <T> ReferenceHolder<T> get(Class<T> clazz, boolean recreateIfExists) {
    if (recreateIfExists && Provider.contains(clazz)) {
    ReferenceHolder<T> refHolder = holder.get(clazz);
    if (refHolder == null) {
        if (isScoped(clazz, ApplicationScoped.class)) {
            refHolder = new ApplicationScopedReferenceHolder<T>(clazz);
        } else if (isScoped(clazz, PrototypeScoped.class)) {
            refHolder = new PrototypeScopedReferenceHolder<T>(clazz);
        } else {
            throw new IllegalStateException(String.format("No scope defined on clazz %s!", clazz.getCanonicalName()));
        holder.put(clazz, refHolder);
        if (clazz.isAnnotationPresent(Named.class)) {
            holderNamed.put(clazz.getAnnotation(Named.class).value(), refHolder);
    return refHolder;

public abstract static class ReferenceHolder<Z> {
    public abstract Z instance();
    public abstract Z instance(PrototypeContext prototypeContext);

So… there is something like instance(). Now I wonder why IDE don’t see it. Probably IDE see Java’s provider first. Is it possible? Can’t wait to come back to my home and look at it once again.

If it’s imported directly then that’s the one that should be used.

If the compiler compiles it just fine and the IDE is still complaining then it’s just an IDE bug, I guess.

When I still used the SDK, I had so many classes that were flagged with errors incorrectly that I just turned that feature off after a while.

This is not an error in JME’s SDK, I have it in IntelliJ. Main class and Provider are in different project, the one with mainclass have Java and some big compiled Jar in its dependencies. That jar is build with maven, it have all projects and some 3rd party libraries… I think that it is much more complicated as it should be. I’ll try to change dependency order for project with mainclass.

Make sure you are using the Runtime class from jade.core, not java.lang.

You are welcome.

1 Like