B4J Question Items from Javaobject in Log but not in Listview

Sifu

Active Member
Hello,

The below code is checking files in a selected folder and uses the Java code I found here in the forum.
Why do I see the JavaObject contents as Items in the Log but not in the Listview?

Perhaps I'm doing something wrong, could someone point me how to fix this?

B4X:
Sub GetTheFolderContents (fldr As String)
    'Log("fldr=" & fldr)
    Dim folders As List
    folders.Initialize
    folders.Add(fldr)
    fList.Initialize
   
    Dim JO As JavaObject = Me
    Dim FilePath As String
   
    Do While folders.Size > 0
        fldr = folders.Get(0)
        folders.RemoveAt(0)
        Label5TotalNrFiles.Text = fList.Size
        Sleep(0)
        Dim entries As List = File.ListFiles(fldr)
        If entries.IsInitialized Then
            For Each x As String In entries
                If File.IsDirectory(fldr, x) Then
                    folders.Add(File.Combine(fldr, x)) ' Found a subfolder
                Else
                    FilePath = (fldr & "\" & x)
                    JO.RunMethod("FileDetails",Array(FilePath))
                    'Log("FileDetails: " & Array(FilePath))
                  
                    'try to get each item from returned javaobject array
                    Dim myArray(4) As String
                    myArray = Array As String(FilePath)

                    'For i = 0 To myArray.Length - 1
                    '    Dim currentItem As String = myArray(i)
                    '    Dim itemNumber As Int = i + 1 ' Adding 1 to get the actual item number (1-based index)
                    '    Log("Item number: " & itemNumber & ", Item: " & currentItem)
                    '    ListView1.Items.Add("Item number: " & itemNumber & ", Item: " & currentItem)
                    'Next
                   
                    For Each item As String In myArray
                        ' Do something with the current item, for example, print it:
                    ListView1.Items.Add("Item: " & item)
                        Log("Item: " & item)
                    Next
                   
                End If
            Next
        End If
    Loop
End Sub

#if java
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
    public static void FileDetails(String filePath)    {
        File file = new File(filePath); //with \ escape pattern for backslashes
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getName());
        System.out.println(file.length()); //Size
        System.out.println(new Date(file.lastModified()));
        //System.out.println(file.getAbsolutePath() + "," + file.getName() + "," + file.length() + "," + new Date(file.lastModified()));
    }
#End If

What I need is the full pathname including filename, Filenam, Size, and the date of the file. The last 3 do not need to be in the Listview necessarily, they could be in a variable so they all can be added to a Database.

Thanks for any help.
 
Last edited:

Sifu

Active Member
Are you suggesting that to get the relevant File info, I do not need any Java code and can do only with B4J (libraries)?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
The in-line java method is declared void, so will never return anything. The reason you see it in the log is the System.out.println(...) which writes to stdout.
 
Upvote 0

Sifu

Active Member
OK thanks. I know very little about Java.
I will do some further investigation how to handle this. Thanks for the heads up.
 
Upvote 0
Top