I'm new to B4A and tried with the help of ChatGPT try to built a Android APP that allows to transfer Photos from a Smartphone to a Windows Server via WLAN. The core function does not work. I tried to use jcifs-ngV0.32 but I am not able to start it. the error message is:
Fehler: java.lang.ClassNotFoundException: jcifs$CIFSContext
(ClassNotFoundException) java.lang.ClassNotFoundException: jcifs$CIFSContext
I have the impression that ChatGPT relied on this Library and it does not work and doesn't admit that we are in the middle of nowhere.
this is the sub:
Sub KopiereVomSmartphoneZuSMB(p_Map As Map, zielKey As String)
Log("KopiereVomSmartphoneZuSMB: Start, Key=" & zielKey)
Try
Dim quellPfad As String = p_Map.Get("Quellpfad")
Dim zielPfad As String = ""
Dim benutzer As String = p_Map.GetDefault("SMBUser", "")
Dim passwort As String = p_Map.GetDefault("SMBPass", "")
If p_Map.ContainsKey(zielKey) = False Then
ToastMessageShow("Zielpfad nicht gefunden: " & zielKey, True)
Return
End If
Dim eintrag As Map = p_Map.Get(zielKey)
zielPfad = eintrag.Get("Pfad")
If quellPfad = "" Or zielPfad = "" Then
ToastMessageShow("Quell- oder Zielpfad fehlt.", True)
Return
End If
Log("Quelle: " & quellPfad)
Log("Ziel: " & zielPfad)
' Authentifizierung
Dim jcifs As JavaObject
jcifs.InitializeStatic("jcifs.CIFSContext")
Dim baseContext As JavaObject = jcifs.RunMethod("getSystemInstance", Null)
Dim NtlmAuth As JavaObject
NtlmAuth.InitializeNewInstance("jcifs.smb.NtlmPasswordAuthenticator", Array(benutzer, passwort))
Dim authContext As JavaObject = baseContext.RunMethodJO("withCredentials", Array(NtlmAuth))
' Ziel vorbereiten
Dim zielFolder As JavaObject
zielFolder.InitializeNewInstance("jcifs.smb.SmbFile", Array(zielPfad, authContext))
If zielFolder.RunMethod("exists", Null) = False Then
zielFolder.RunMethod("mkdir", Null)
End If
' Lokale Dateien lesen
Dim files As List = File.ListFiles(quellPfad)
If files.IsInitialized Then
Log("Gefundene Dateien:")
For Each f As String In files
Log(f)
Next
Else
Log("Liste ist nicht initialisiert")
End If
If files.IsInitialized = False Then
ToastMessageShow("Quellverzeichnis nicht lesbar.", True)
Return
End If
For Each dateiname As String In files
If File.IsDirectory(quellPfad, dateiname) = False Then
Log("Kopiere: " & dateiname)
Dim lokalInput As InputStream = File.OpenInput(quellPfad, dateiname)
Dim zielDatei As JavaObject
zielDatei.InitializeNewInstance("jcifs.smb.SmbFile", Array(zielPfad & "/" & dateiname, authContext))
Dim smbOutput As OutputStream = zielDatei.RunMethod("getOutputStream", Null)
CopyStream(lokalInput, smbOutput)
End If
Next
ToastMessageShow("Kopiervorgang abgeschlossen.", False)
Catch
Log("Fehler: " & LastException.Message)
Log(LastException) ' Gibt Stacktrace
ToastMessageShow("Fehler beim Kopieren vom Smartphone.", True)
End Try
End Sub
I controlled, several times, that the Libraries are at the right place and have the right names. It is introduced:
#AdditionalJar: jcifs-ng-smb-client.jar
My question: Is there any possibility to bring this project to a happy end, or should I start from scratch using another technique.
Dirk
Fehler: java.lang.ClassNotFoundException: jcifs$CIFSContext
(ClassNotFoundException) java.lang.ClassNotFoundException: jcifs$CIFSContext
I have the impression that ChatGPT relied on this Library and it does not work and doesn't admit that we are in the middle of nowhere.
this is the sub:
Sub KopiereVomSmartphoneZuSMB(p_Map As Map, zielKey As String)
Log("KopiereVomSmartphoneZuSMB: Start, Key=" & zielKey)
Try
Dim quellPfad As String = p_Map.Get("Quellpfad")
Dim zielPfad As String = ""
Dim benutzer As String = p_Map.GetDefault("SMBUser", "")
Dim passwort As String = p_Map.GetDefault("SMBPass", "")
If p_Map.ContainsKey(zielKey) = False Then
ToastMessageShow("Zielpfad nicht gefunden: " & zielKey, True)
Return
End If
Dim eintrag As Map = p_Map.Get(zielKey)
zielPfad = eintrag.Get("Pfad")
If quellPfad = "" Or zielPfad = "" Then
ToastMessageShow("Quell- oder Zielpfad fehlt.", True)
Return
End If
Log("Quelle: " & quellPfad)
Log("Ziel: " & zielPfad)
' Authentifizierung
Dim jcifs As JavaObject
jcifs.InitializeStatic("jcifs.CIFSContext")
Dim baseContext As JavaObject = jcifs.RunMethod("getSystemInstance", Null)
Dim NtlmAuth As JavaObject
NtlmAuth.InitializeNewInstance("jcifs.smb.NtlmPasswordAuthenticator", Array(benutzer, passwort))
Dim authContext As JavaObject = baseContext.RunMethodJO("withCredentials", Array(NtlmAuth))
' Ziel vorbereiten
Dim zielFolder As JavaObject
zielFolder.InitializeNewInstance("jcifs.smb.SmbFile", Array(zielPfad, authContext))
If zielFolder.RunMethod("exists", Null) = False Then
zielFolder.RunMethod("mkdir", Null)
End If
' Lokale Dateien lesen
Dim files As List = File.ListFiles(quellPfad)
If files.IsInitialized Then
Log("Gefundene Dateien:")
For Each f As String In files
Log(f)
Next
Else
Log("Liste ist nicht initialisiert")
End If
If files.IsInitialized = False Then
ToastMessageShow("Quellverzeichnis nicht lesbar.", True)
Return
End If
For Each dateiname As String In files
If File.IsDirectory(quellPfad, dateiname) = False Then
Log("Kopiere: " & dateiname)
Dim lokalInput As InputStream = File.OpenInput(quellPfad, dateiname)
Dim zielDatei As JavaObject
zielDatei.InitializeNewInstance("jcifs.smb.SmbFile", Array(zielPfad & "/" & dateiname, authContext))
Dim smbOutput As OutputStream = zielDatei.RunMethod("getOutputStream", Null)
CopyStream(lokalInput, smbOutput)
End If
Next
ToastMessageShow("Kopiervorgang abgeschlossen.", False)
Catch
Log("Fehler: " & LastException.Message)
Log(LastException) ' Gibt Stacktrace
ToastMessageShow("Fehler beim Kopieren vom Smartphone.", True)
End Try
End Sub
I controlled, several times, that the Libraries are at the right place and have the right names. It is introduced:
#AdditionalJar: jcifs-ng-smb-client.jar
My question: Is there any possibility to bring this project to a happy end, or should I start from scratch using another technique.
Dirk