B4J Question DirAssets under Windows 11

johnmie

Active Member
Licensed User
Longtime User
Just bought a new computer with Windows 11 on it. Now my app does not seem to recognize DirAssets any more:

B4X:
    MainForm.Show
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
    Log("URI = "&File.GetUri(File.DirAssets, "")&"  Urfolder = "&Z.urfolder)
    MainForm.Icon = fx.LoadImage(Z.urfolder, "Vicon.png") 'File.DirAssets

The log shows: URI = file:/C:/Drive_E/!!B4X/!!Quasi/QuasiList28/B4J/Files/ Urfolder = file:/C:/Drive_E/!!B4X/!!Quasi/QuasiList28/B4J/Files/
File Vicon.png exists in Explorer under: C:\Drive_E\!!B4X\!!Quasi\QuasiList28\B4J\Files

And the program crashes with:
Error encountered:
Error occurred on line: 18 (Main)
java.io.FileNotFoundException: file:\C:\Drive_E\!!B4X\!!Quasi\QuasiList28\B4J\Files\Vicon.png (The filename, directory name, or volume label syntax is incorrect)
    at java.base/java.io.FileInputStream.open0(Native Method)
    at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:244)
    at anywheresoftware.b4j.objects.ImageViewWrapper$ImageWrapper.Initialize(ImageViewWrapper.java:138)
    at anywheresoftware.b4j.objects.JFX.LoadImage(JFX.java:163)
    at b4j.B4XPagesNavBar.main._appstart(main.java:101)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.B4XPagesNavBar.main.start(main.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)

Is there a problem with the volume label syntax or do I need to download/install another Java version?

Your help is greatly appreciated. Thank you,
john m.
 

LDeeJay

Member
How is Z defined? If I load
B4X:
MainForm.Icon = fx.LoadImage(File.DirAssets, "Vicon.png") 'File.DirAssets
It works as expected and the form icon is set (also under Windows11). Even tested it with the special characters (!!) in the folder names. So I suspect Z instead of File.DirAssets.
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
Have you just tried:
B4X:
fx.LoadImage(File.DirAssets, "Vicon.png")

or
B4X:
Z.urfolder = File.DirAssets
fx.LoadImage(Z.urfolder, "Vicon.png")

Log(File.DirAssets) = "AssetsDir", <> "file:/C:/...."
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Just bought a new computer with Windows 11 on it. Now my app does not seem to recognize DirAssets any more:

B4X:
    MainForm.Show
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
    Log("URI = "&File.GetUri(File.DirAssets, "")&"  Urfolder = "&Z.urfolder)
    MainForm.Icon = fx.LoadImage(Z.urfolder, "Vicon.png") 'File.DirAssets

The log shows: URI = file:/C:/Drive_E/!!B4X/!!Quasi/QuasiList28/B4J/Files/ Urfolder = file:/C:/Drive_E/!!B4X/!!Quasi/QuasiList28/B4J/Files/
File Vicon.png exists in Explorer under: C:\Drive_E\!!B4X\!!Quasi\QuasiList28\B4J\Files


I am sure your app was running in debug mode.
B4X:
File.GetUri(File.DirAssets, "")
1. It is a wrong usage, you should give a filename existed instead of "", or you will get a warning File is missing and app will crash in release mode
B4X:
MainForm.Icon = fx.LoadImage(Z.urfolder, "Vicon.png") 'File.DirAssets
2. You can't use "!" as folder name in DirAssets, as Erel said It will become part of jar file.
 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
I know File.DirAssets works also under Windows 11, but I needed to find the absolute location to be able to communicate with other parts of the program, so here is my workaround (after removing leading !! from directory names):
B4X:
    UrFolder = File.GetUri(File.DirAssets,"Vicon.png")
    Log("File.DirAssets first. = "&UrFolder)
    UrFolder = UrFolder.SubString2(0,UrFolder.lastindexof("/"))
    UrFolder = UrFolder.Replace("/","\")
    UrFolder = UrFolder.SubString(UrFolder.IndexOf("\")+1)
    Log("File.DirAssets abs. = "&UrFolder)

And this is the log result:
File.DirAssets first. = file:/C:/_E/B4X/Quasi/Quasi_25/B4J/Files/Vicon.png
File.DirAssets abs. = C:\_E\B4X\Quasi\Quasi_25\B4J\Files

I'm sure there are more elegant ways.
 
Upvote 0
Top