Android Question Problem with jcifs-ng library

PierPaduan

Active Member
Licensed User
Longtime User
Hi.
I'm using a Samsung Tab E with Android 4.4.4.
I'm making some tests sharing files between Android and Windows using the DonManfred's library and the example found here:
and other code found here:

My example is attached.

I have no problems if, in Debug Mode, I copy a file from Windows to Android or viceversa, or I try to delete a file on Windows from my Android device.

Problems comes when I'm in Release Mode.
When I'm performing the sub lvFiles_ItemClick ( with the execution of the smbclient.Copy) or the BtnnCopy_Click (with the execution of the smbclient.Copy2) the stop of the app is obtained and the Logs write:
java.lang.Exception: Sub smbclient_copyprogress was not found. at anywheresoftware.b4a.BA.raiseEvent2(BA.java:202) at anywheresoftware.b4a.BA$2.run(BA.java:370) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5590) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) at dalvik.system.NativeStart.main(Native Method)

When I'm performing the lvFiles_ItemLongClick (with the execution of the smbclient.delete) the stop of the app is obtained and the Logs write:
java.lang.Exception: Sub smbclient_delete was not found. at anywheresoftware.b4a.BA.raiseEvent2(BA.java:202) at anywheresoftware.b4a.BA$2.run(BA.java:370) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5590) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) at dalvik.system.NativeStart.main(Native Method)

Someone can help me to fix this problem?
Thanks a Lot to everyone.
 

Attachments

  • jcifs-ng-example-with-modifications.zip
    14.9 KB · Views: 356

DonManfred

Expert
Licensed User
Longtime User
java.lang.Exception: Sub smbclient_copyprogress was not found.

Create the missing sub

Add the sub to the starter service or wherever you are using it

B4X:
Sub SMBClient_CopyProgress(totalBytes As Long, path As String, filename As String)
    Log($"SMBClient_CopyProgress(${totalBytes} : ${path}:${filename})"$)
End Sub
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
Create the missing sub

Add the sub to the starter service or wherever you are using it

B4X:
Sub SMBClient_CopyProgress(totalBytes As Long, path As String, filename As String)
    Log($"SMBClient_CopyProgress(${totalBytes} : ${path}:${filename})"$)
End Sub

Hi DonManfred.
Unfortunately the CopyProgress was already in the Starter code. See this screenshot please.
View attachment 92854
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
        If Result = DialogResponse.POSITIVE Then
            smbclient.Initialize("SMBClient",Main.credentials.Domain,Main.credentials.Username,Main.credentials.Password,Main.credentials.Share)
            smbclient.delete(Value)
            
            CallSub2(Starter,"SMBInit",Main.credentials)

        End If

This code is unuseful.

Try it this way

B4X:
        If Result = DialogResponse.POSITIVE Then
            Starter.smbClient.delete(Value)
        End If
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
B4X:
        If Result = DialogResponse.POSITIVE Then
            smbclient.Initialize("SMBClient",Main.credentials.Domain,Main.credentials.Username,Main.credentials.Password,Main.credentials.Share)
            smbclient.delete(Value)
           
            CallSub2(Starter,"SMBInit",Main.credentials)

        End If

This code is unuseful.

Try it this way

B4X:
        If Result = DialogResponse.POSITIVE Then
            Starter.smbClient.delete(Value)
        End If

Hi.
Using your advice the app crash in debug mode too and the exception is the same: "Sub smbclient_delete was not found".
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
No, it is new/another error/another missing eventsub. Do you have the event sub in your starter service?

Hi.
The Starter is the following. The Sub smbclient_delete is not in the Starter, but I would like to understand why the copy and the delete works correctly in debug but not in release.
B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region


Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public rp As RuntimePermissions
    Public smbClient As SMBClient
    Public glRes, github As SMBResource

End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
End Sub
Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub

#Region SMB
Sub SMBInit(cred As SMBCred)
    smbClient.Initialize("SMBClient",cred.Domain,cred.Username,cred.Password,cred.Share)
End Sub
Sub SMBClient_CopyProgress(totalBytes As Long, path As String, filename As String)
    Log($"SMBClient_CopyProgress(${totalBytes} : ${path}:${filename})"$)
End Sub
Sub SMBClient_Resource(success As Boolean, smbobjres As Object,smbobj As Object, info As String)
    Log($"SMBClient_Resource(${success},${info},${smbobjres},${smbobj})"$)
    If smbobjres <> Null And smbobj <> Null And info = "OK" Then
        Dim smbResource As SMBResource = smbobjres
        glRes = smbResource
        
        Dim smbfile As SMBFile = smbobj

        Log($"SMBClient_Resource(${smbResource}, ${smbfile})"$)
        Log($"CanonicalPath = ${smbfile.CanonicalPath}"$)
        Log($"CanonicalUncPath = ${smbfile.CanonicalUncPath}"$)
        

        'Dim flist As List = smbfile.listFiles
        'Log($"ListFiles2(res,"*.tif")"$)
        'jcifs.listFiles2(smbfile,"*.tif")




        
    '    cmbClient.GetResourcefromUrl("smb://192.168.192.168/SMBTest/")
    '    wait for SMBClient_Resource(smbobjres2 As Object,smbobj2 As Object)
    '    Log("GithubShare found...")
    '    github = smbobjres2
    '    Dim SMBTestOrdner As SMBFile = smbobj2
    '    Log($"${SMBTestOrdner.CanonicalPath}"$)
    '    Log($"ListFiles2(res)"$)
        smbClient.listFiles(smbResource)
    End If

    
End Sub
Sub SMBClient_ListFiles(filelist As List)
    Log($"SMBClient_ListFiles(${filelist})"$)
    Dim koeln As SMBFile
    Dim dn As SMBFile
    Dim tocopy As SMBFile
    If filelist.IsInitialized And filelist.Size > 0 Then
        For i=0 To filelist.Size-1
            Dim f As SMBFile = filelist.Get(i)
            Log($"FILE CanonicalPath = ${f.CanonicalPath} (${f.length})"$)
            'FILE CanonicalPath = smb://192.168.192.168/GeoTIFs/koeln/ (0)
            If i = 0 Then
                'Log($"Device->Share CanonicalPath = ${f.CanonicalPath} (f.length)"$)
                'jcifs.Copy2(File.DirRootExternal,"Gesamtvh.tif",glRes,"GesamtSMB.tif")
                
            End If
            'Log($"ContentEncoding = ${f.ContentEncoding}"$)

            'Log($"Length = ${f.length}"$)
            If f.CanonicalPath = "smb://192.168.192.168/GeoTIFs/dn/" Then
                Log("Resourcefolder DN found...")
                dn = f
            End If
            

            If f.CanonicalPath = "smb://192.168.192.168/GeoTIFs/koeln/" Then
                Log("Resourcefolder KOELN found...")
                koeln = f
                
                'Log("To be sure. It is deleted if already copied for Test")
                'If File.Exists(File.DirRootExternal,"Gesamtvh.tif") Then
                '    Log("Delete File")
                '    File.Delete(File.DirRootExternal,"Gesamtvh.tif")
                '    Log("File deleted")
                'End If
                'Log($"Copy file = Gesamtvh.tif"$)
                'jcifs.Copy(f,File.DirRootExternal,"Gesamtvh.tif")
'                Dim os As OutputStream = File.OpenOutput(File.DirInternal,"Gesamt.jpg",False)
'                Dim Ins As InputStream = f.InputStream
'                File.Copy2(Ins,os)
'                os.Close
            End If
            
            
        Next
        'Dim dest As SMBFile = smbClient.CreateSmbFile(koeln,"kopieX")
        'dn.copyTo(dest)

        CallSubDelayed2(actSMBFiles,"LoadFiles",filelist)
    End If

    'smbClient.CopyTo(dn,dest) ' dn und dst sind jeweils SmbFile

'    cmbClient.GetResourcefromUrl("file://192.168.192.168/$d/")
'    wait for SMBClient_Resource(smbobjres2 As Object,smbobj2 As Object)
'    Log("GithubShare found...")
'    github = smbobjres2
'    Dim SMBTestOrdner As SMBFile = smbobj2
'    Log($"${SMBTestOrdner.CanonicalPath}"$)
'    Log($"ListFiles2(res)"$)
    'smbClient.delete(dn)
End Sub
Sub SMBClient_CopyTo(success As Boolean)
    
End Sub
Sub SMBClient_CopyResult(success As Boolean, path As String, filename As String)
    Log($"SMBClient_CopyResult(${success})"$)
End Sub
#End Region

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
In debug mode b4a is much less restrictive.

Run your project in release mode. When it crashes then you need to fix something.
Hi.
Restarting from your example here: https://www.b4x.com/android/forum/threads/jcifs-ng-smb-client-smb2.104560/#content and studying it more deeply I has been able to copy from Android to the shared network folder and viceversa. I has been able to delete a file in the the shared network folder as well. I would like just to report that the Delete event Sub is not as you write:
  • Delete (success As Boolean, toDelete As SmbFile)
but it's this one:
  • Delete (success As Boolean)
Don, Thank You Very Much for your library. It's very very useful.
Regards.
 
Upvote 0

Ninja33

Member
Hi.
The Starter is the following. The Sub smbclient_delete is not in the Starter, but I would like to understand why the copy and the delete works correctly in debug but not in release.
B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region


Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public rp As RuntimePermissions
    Public smbClient As SMBClient
    Public glRes, github As SMBResource

End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
End Sub
Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub

#Region SMB
Sub SMBInit(cred As SMBCred)
    smbClient.Initialize("SMBClient",cred.Domain,cred.Username,cred.Password,cred.Share)
End Sub
Sub SMBClient_CopyProgress(totalBytes As Long, path As String, filename As String)
    Log($"SMBClient_CopyProgress(${totalBytes} : ${path}:${filename})"$)
End Sub
Sub SMBClient_Resource(success As Boolean, smbobjres As Object,smbobj As Object, info As String)
    Log($"SMBClient_Resource(${success},${info},${smbobjres},${smbobj})"$)
    If smbobjres <> Null And smbobj <> Null And info = "OK" Then
        Dim smbResource As SMBResource = smbobjres
        glRes = smbResource
       
        Dim smbfile As SMBFile = smbobj

        Log($"SMBClient_Resource(${smbResource}, ${smbfile})"$)
        Log($"CanonicalPath = ${smbfile.CanonicalPath}"$)
        Log($"CanonicalUncPath = ${smbfile.CanonicalUncPath}"$)
       

        'Dim flist As List = smbfile.listFiles
        'Log($"ListFiles2(res,"*.tif")"$)
        'jcifs.listFiles2(smbfile,"*.tif")




       
    '    cmbClient.GetResourcefromUrl("smb://192.168.192.168/SMBTest/")
    '    wait for SMBClient_Resource(smbobjres2 As Object,smbobj2 As Object)
    '    Log("GithubShare found...")
    '    github = smbobjres2
    '    Dim SMBTestOrdner As SMBFile = smbobj2
    '    Log($"${SMBTestOrdner.CanonicalPath}"$)
    '    Log($"ListFiles2(res)"$)
        smbClient.listFiles(smbResource)
    End If

   
End Sub
Sub SMBClient_ListFiles(filelist As List)
    Log($"SMBClient_ListFiles(${filelist})"$)
    Dim koeln As SMBFile
    Dim dn As SMBFile
    Dim tocopy As SMBFile
    If filelist.IsInitialized And filelist.Size > 0 Then
        For i=0 To filelist.Size-1
            Dim f As SMBFile = filelist.Get(i)
            Log($"FILE CanonicalPath = ${f.CanonicalPath} (${f.length})"$)
            'FILE CanonicalPath = smb://192.168.192.168/GeoTIFs/koeln/ (0)
            If i = 0 Then
                'Log($"Device->Share CanonicalPath = ${f.CanonicalPath} (f.length)"$)
                'jcifs.Copy2(File.DirRootExternal,"Gesamtvh.tif",glRes,"GesamtSMB.tif")
               
            End If
            'Log($"ContentEncoding = ${f.ContentEncoding}"$)

            'Log($"Length = ${f.length}"$)
            If f.CanonicalPath = "smb://192.168.192.168/GeoTIFs/dn/" Then
                Log("Resourcefolder DN found...")
                dn = f
            End If
           

            If f.CanonicalPath = "smb://192.168.192.168/GeoTIFs/koeln/" Then
                Log("Resourcefolder KOELN found...")
                koeln = f
               
                'Log("To be sure. It is deleted if already copied for Test")
                'If File.Exists(File.DirRootExternal,"Gesamtvh.tif") Then
                '    Log("Delete File")
                '    File.Delete(File.DirRootExternal,"Gesamtvh.tif")
                '    Log("File deleted")
                'End If
                'Log($"Copy file = Gesamtvh.tif"$)
                'jcifs.Copy(f,File.DirRootExternal,"Gesamtvh.tif")
'                Dim os As OutputStream = File.OpenOutput(File.DirInternal,"Gesamt.jpg",False)
'                Dim Ins As InputStream = f.InputStream
'                File.Copy2(Ins,os)
'                os.Close
            End If
           
           
        Next
        'Dim dest As SMBFile = smbClient.CreateSmbFile(koeln,"kopieX")
        'dn.copyTo(dest)

        CallSubDelayed2(actSMBFiles,"LoadFiles",filelist)
    End If

    'smbClient.CopyTo(dn,dest) ' dn und dst sind jeweils SmbFile

'    cmbClient.GetResourcefromUrl("file://192.168.192.168/$d/")
'    wait for SMBClient_Resource(smbobjres2 As Object,smbobj2 As Object)
'    Log("GithubShare found...")
'    github = smbobjres2
'    Dim SMBTestOrdner As SMBFile = smbobj2
'    Log($"${SMBTestOrdner.CanonicalPath}"$)
'    Log($"ListFiles2(res)"$)
    'smbClient.delete(dn)
End Sub
Sub SMBClient_CopyTo(success As Boolean)
   
End Sub
Sub SMBClient_CopyResult(success As Boolean, path As String, filename As String)
    Log($"SMBClient_CopyResult(${success})"$)
End Sub
#End Region

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub
How did you solve the problem that it works in debug mode, but not in release mode?
 
Upvote 0
Top