B4J Question FileNotFoundException on line: 23 (XLReader)

mfstuart

Active Member
Licensed User
Longtime User
Why is this code throwing this error?

B4X:
Private Sub lvSheets_SelectedIndexChanged(Index As Int)
    Dim filename As String = txtFilename.Text
   
    If File.Exists("", filename) Then
        Dim sheetname As String = lvSheets.Items.Get(Index)
       
        'get sheet data
        XL.Initialize
        Dim result As XLReaderResult = XL.Reader.ReadRange("", filename, sheetname & "!A3:F100")     '<<==== error thrown here
        result.LogResult(True)
       
        'set table column names
        tbSheetData.AddColumn(result.Get(XL.AddressName("A2")), tbSheetData.COLUMN_TYPE_TEXT)
        tbSheetData.AddColumn(result.Get(XL.AddressName("B2")), tbSheetData.COLUMN_TYPE_TEXT)
        tbSheetData.AddColumn(result.Get(XL.AddressName("C2")), tbSheetData.COLUMN_TYPE_TEXT)
        tbSheetData.AddColumn(result.Get(XL.AddressName("D2")), tbSheetData.COLUMN_TYPE_TEXT)
        tbSheetData.AddColumn(result.Get(XL.AddressName("E2")), tbSheetData.COLUMN_TYPE_TEXT)
        tbSheetData.AddColumn(result.Get(XL.AddressName("F2")), tbSheetData.COLUMN_TYPE_TEXT)      
    Else
        xui.MsgboxAsync("File not found!", "Error")
    End If
End Sub

Thanx in advance,
Mark Stuart

Edit: adding full error log:
B4X:
Waiting for debugger to connect...
Program started.
Error occurred on line: 23 (XLReader)
java.io.FileNotFoundException: \C:\Projects\B4J\XLS_Read_Approval_Levels\Approval Levels.xlsx
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:268)
    at anywheresoftware.b4j.objects.PoiWorkbookWrapper.InitializeExisting(PoiWorkbookWrapper.java:78)
    at b4j.example.xlreader._openworkbook(xlreader.java:328)
    at b4j.example.xlreader._readranges(xlreader.java:563)
    at b4j.example.xlreader._readrange(xlreader.java:56)
    at b4j.example.main._lvsheets_selectedindexchanged(main.java:173)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$1.run(BA.java:233)
    at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:185)
    at java.lang.Thread.run(Thread.java:748)
 
Last edited:

mfstuart

Active Member
Licensed User
Longtime User
there is a \ before the C:\
I noticed that in the error log as well.
I looked for it but couldn't find it, even using Log(filename) and seeing its value in the Logs.
It is not there.

I think it is something in the XLUtils library, as the error references line 23 in XLReader.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
XL.Reader.ReadRange("", filename
i guess the "" means the folder, i guess the library adds it.

break filename in 2, file.getparent and file.getname, and use those instead of writing "", i know you are doing a file exists, but XL innards are different.
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
@Erel,
Can you please look into the XLUtils for the "\" before the filename in the Logs used in this example?

Thanx,
Mark Stuart
 
Upvote 0
Top