skip to Main Content

I have a kotlin activity used as splashscreen to check if the user is already logged in using Google services or not. After awaiting 600ms it should create an intent to redirect the user on the LoginActivity or MainActivity using the ActiviyClass::class.java

For some reason Android studio marks "java" in red and tells "Unresolved reference: java", where did i mess up?

Code:

 var intent = Intent(this, MainActivity::class.java)

        if(!isLoggedIn()){
            intent = Intent(this, LoginActivity::class.java)
        }

Explanatory image here

4

Answers


  1. I’d try invalidate cache & restart, or check project’s java dependency

    Login or Signup to reply.
  2. Mostly these type of issues are related to tool that you are using i.e Android studio. I have copied your code and pasted in my project and its working perfect.

    Please look screen shot attached.

    enter image description here

    Possible solution :

    1- Try invalidate cache and restart your Android studio. I am attaching screen shot of place where you can find this option.

    enter image description here

    Happy coding!!

    Login or Signup to reply.
  3. You directly start MainActivity before checking !isLoggedIn() condition. That’s why you facing this error. I’m a java developer but I think the problem is here

    make your code as below I changed.

            
            if(!isLoggedIn()){
                var intent = Intent(this, LoginActivity::class.java)
            }
            else{
            var intent = Intent(this, MainActivity::class.java)
            }
    

    Hope this helps

    Login or Signup to reply.
  4. 1. Solution

    Looks like you are using Kotlin2Js. If you are using the idea to compile the code, make sure your project settings are set to Kotlin(JVM) and not Kotlin Java Script.

    if the above solution does not work then try to do the second solution

    2. Solution

    Try to invalidate caches

    goto -> File -> Invalidate caches -> click on Invalidate and Restart button

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search