2

I reformatted my mac recently and installed everything from scratch. So I did it with Android Studio too and then I imported an existing project of mine.

Screenshot

As you can see in the screenshot, when I use Long.parseLong(), Android Studio is telling me that it is not a valid function but it is a valid function in Kotlin.

How do I fix this?

Previous Attempts to fix. 1. Reinstall JDK and JRE 2. Reinstall Android Studio 3. Clean and Rebuild gradle 4. Android Studio -> File -> Invalidate Caches/Restart

None of these steps worked. What is wrong with my Android Studio?

3
  • 1
    Check your import statements if it is correct. Commented Jan 10, 2019 at 9:29
  • Yup. Got this import java.util.* Commented Jan 10, 2019 at 9:30
  • Long class is in the java.lang package, not java.util Commented Jan 10, 2019 at 9:39

2 Answers 2

4

It's Kotlin, not Java

Compiler tries to use Long class from the Kotlin library, the class doesn't have parseLong() method.

You have two options:

Fully qualify class (add the package name)

java.lang.Long.parseLong(msg.time)

Or more "Kotlin way"

msg.time.toLong()
Sign up to request clarification or add additional context in comments.

Comments

0
parseLong(val); 

Is a java method and this is Kotlin. Android Studio is working fine.

You don't need to do anything with Android Studio.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.