2

I tried to import the java.nio.file.Files class in Android Studio and the Files part of the import statement turns red and messages that it can't be resolved. The class is definitely in the External Libraries folder, I can navigate to it and see that it's there. What might be causing this?

Jpaji Rajnish
  • 1,491
  • 4
  • 17
  • 35

1 Answers1

2

The Android Platform Runtime Environment is similar to common (Oracle or OpenJDK) Java Runtime Environment but it is not the same.

Therefore classes that exist in Java 1.6/1.7/1.8 may exist on Android as well but they can also be missing. If they exist you can use them if not you can't.

The package java.nio.file.* for example is not available on Android. If you have code that requires this package you have to rewrite it.

Even if the Java Runtime is added by default to your project as external library this is done only for compatibility reasons. You can not use classes from this library.

Robert
  • 39,162
  • 17
  • 99
  • 152
  • This seems pretty ridiculous that the java.nio.file packages are not available on Android when I'm referencing Google example documentation for code that requires those imports. Now I have to figure out another way. Sigh....I hate wasting time having to fix example code from Google! – gbotha Sep 13 '15 at 05:46
  • ok, but it still issue... Who know which kind of library we should use instead of? – Sirop4ik May 02 '16 at 08:37