Search code examples
javaandroidoopandroid-studiohotswap

Android Studio Apply Changes non-static method cannot be referenced, but method is static


I have a problem compiling my android app in Android Studio. I get an error like this:

Error:(51, 48) error: non-static method buildUsernameUrlString(String)
cannot be referenced from a static context

Also this one:

Error:(63, 38) error: OAUTH_URL has private access in TwitchApi

I'm aware of the concept of static methods etc. which is why I my TwitchApi class looks like this:

public class TwitchApi {
    // more stuff here

    public static String OAUTH_URL = Uri.parse("https://api.twitch.tv/kraken/oauth2/authorize")
            .buildUpon()
            .appendQueryParameter("response_type", "token")
            .appendQueryParameter("client_id", CLIENT_ID)
            .appendQueryParameter("redirect_uri", REDIRECT_URL)
            .appendQueryParameter("scope", "user_read chat_login").build().toString();


    public static String buildUsernameUrlString(String accessToken)
    {
        return BASE_URI
                .buildUpon()
                .appendQueryParameter("client_id", CLIENT_ID)
                .appendQueryParameter("oauth_token", accessToken)
                .build()
                .toString();
    }
}

So my method is clearly static, also public, and the property OAUTH_URL is public and static aswell.

I call the method like this:

String usernameUrlString = TwitchApi.buildUsernameUrlString(matcher.group(1));

What's weird is that I only get this error when doing "Applying Changes" which seems to be like a hot-swap for changes to not compile the entire application again.

A full compilation has no error.

Has anyone any idea how to get around this error? I really like the Apply Changes feature it speeds up development by a lot.


Solution

  • Try to delete .build folder and rebuild the project. It will solve your problem.