java.nio.Paths.get cannot be found

982 views
Skip to first unread message

François Guillot

unread,
May 5, 2014, 6:16:23 PM5/5/14
to javafx...@googlegroups.com
Hi guys,

I started porting a existing desktop Java FX application on android.


- use the gradle build to generated the android project from my java fx distributed jars
- use the generated and build to create my app APK
- send it to the emulator

I know that OpenGL emulation doesn't work, and of course I got
05-05 18:01:26.697: I/javafx(1129): Using libactivity.so
05-05 18:01:26.697: E/libEGL(1129): called unimplemented OpenGL ES API

So I emulated GPU support (use host GPU in AVD settings)
And I got rid of the problem.

>> Does this mean we can use the emulator with java fx ported app ?


But I also got

05-05 18:10:37.800: I/dalvikvm(840): Could not find method java.nio.file.Paths.get, referenced from method com.xxx.helpers.Constants.<clinit>
05-05 18:10:37.800: W/dalvikvm(840): VFY: unable to resolve static method 44476: Ljava/nio/file/Paths;.get (Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
05-05 18:10:37.800: D/dalvikvm(840): VFY: replacing opcode 0x71 at 0x0049
...
05-05 18:10:39.460: W/dalvikvm(840): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/xxx/helpers/Constants;
05-05 18:10:39.460: W/System.err(840): Exception in Application init method
...
05-05 18:10:40.480: I/lens(840): Finishing terminating
05-05 18:10:40.480: V/GLASS(840): Shutting down
05-05 18:10:40.480: I/GLASS(840): DeleteGlobalRef(pApplication(0x1d2003fe))
05-05 18:10:40.480: V/FXActivity(840): notify_glassShutdown
05-05 18:10:40.490: V/FXActivity native(840): Notification queue finished
05-05 18:10:40.490: V/FXActivity(840): FXActivityEventsLoop finished.
05-05 18:10:40.490: V/GLASS(840): Shut down
05-05 18:10:40.530: W/System.err(840): java.lang.reflect.InvocationTargetException
05-05 18:10:40.530: W/System.err(840): at java.lang.reflect.Method.invokeNative(Native Method)
05-05 18:10:40.530: W/System.err(840): at java.lang.reflect.Method.invoke(Method.java:515)
05-05 18:10:40.530: W/System.err(840): at javafxports.android.DalvikLauncher$1.run(DalvikLauncher.java:122)
05-05 18:10:40.530: W/System.err(840): at java.lang.Thread.run(Thread.java:841)
05-05 18:10:40.540: W/System.err(840): Caused by: java.lang.RuntimeException: Exception in Application init method
05-05 18:10:40.540: W/System.err(840): at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:889)
05-05 18:10:40.540: W/System.err(840): at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
05-05 18:10:40.540: W/System.err(840): at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
05-05 18:10:40.540: W/System.err(840): ... 1 more
05-05 18:10:40.540: W/System.err(840): Caused by: java.lang.NoClassDefFoundError: java.nio.file.Paths
05-05 18:10:40.540: W/System.err(840): at com.xxx.helpers.Constants.<clinit>(Unknown Source)
05-05 18:10:40.540: W/System.err(840): at com.xxx.view.MainLauncher.init(Unknown Source)
05-05 18:10:40.540: W/System.err(840): at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:814)
05-05 18:10:40.540: W/System.err(840): ... 3 more


which seems weird since java.nio.file.Paths.get is well defined in jdk 7 (and I would have had an error in my desktop application, wouldn't I ?)

Can you help me with this ? Did I wrongly set the JVM to use ?

Stefan Fuchs

unread,
May 6, 2014, 4:29:25 PM5/6/14
to javafx...@googlegroups.com
Hi François,

good to hear, that you got your javafx application working in the emulator.
When I last tried, it didn't work for me even, if I enabled GPU support.
Perhaps the problem has been fixed with the recent updates of the SDK, will try again.

To your stacktrace:
Our JavaFX port to Android is not using the Oracle JRE and VM, but the Android class library on the dalvik vm.
The Android class library contains only a subset of the classes available in JDK7.
The class java.nio.file.Paths is not part of the Android class library.
See http://developer.android.com/reference/packages.html for a list of available classes.
We add only classes in the javafx namespace plus some required compatibility classes.

I think it should be possible to rewrite your application to use java.io, instead of java.nio.

Regards,

Stefan

François Guillot

unread,
May 7, 2014, 2:48:32 AM5/7/14
to javafx...@googlegroups.com
Hi Stefan,
Thanks for your answer.
Of course, it totally makes sense !

In my desktop application, I'm using java.nio.file.Paths to get some resources (font, images) stored outside of my application jars.

I don't know if it's good practice or not, but it allows me to replace them without recompiling the jars.

But on a mobile device, such as an android phone, you don't have the capability to use resources in this way, do you ?

I mean, the user downloads an APK file through the market and every resources is located inside the apk ?
I guess you can always later on read/write to the device (in a database for example) but the offline resouces shall be stored in the apk.


Actually, that's what the base android class R.java is about : accessing resources.

So for the sake of multi platform programming, I will modify my desktop application to use another way of loading resources, using getClass().getResourceAsStream()
and I will pack everything in my jar.



You solution to use java.io instead of java.nio classes could work, but then how can I store my resources on the device, outside of the apk file ?

What's your insight on that ?
Reply all
Reply to author
Forward
0 new messages