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)
}
4
Answers
I’d try invalidate cache & restart, or check project’s java dependency
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.
Possible solution :
1- Try invalidate cache and restart your Android studio. I am attaching screen shot of place where you can find this option.
Happy coding!!
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 heremake your code as below I changed.
Hope this helps
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