简体   繁体   中英

Unresolved Java compilation problem for Singleton “getInstance” function

I'm trying to instantiate a Singleton class in Java with VS Code. Everytime the compiler touches the function it throws an "Unresolved Compilation Problem".

I tried creating another Singleton class and the same error applies. I thought it might be some problem of the Java Compiler so I put a few Debug.Log's before but they show up. The problem only apears with the Singleton.

In the main class:

public static void main(String[] args) 
{
    GameManager gm = GameManager.getInstance();
    //gm.Start();
}

In the GameManager class:

private static GameManager instance = null;
private GameManager() {}
public static GameManager getInstance()
{
    if ( instance == null )
    {
        instance = new GameManager();
    }
    return instance;
}

I expected to get the instance of GameManager, instead it throws an "Exception in thread "main" java.lang.Error: Unresolved compilation problem" on the "public static GameManager getInstance()" line.

It turns out it was a VS Code problem.

Installed Eclipse and everything works fine now.

I don't know it it's specific to VSCode, but I'm gonna put more details in this.

This happened on KDE Neon 5.17 , VSCode 1.39.2 and Java 8 OpenJDK .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM