Android Question cc_resut null object reference using ContentChooser

scsjc

Well-Known Member
Licensed User
Longtime User
Hello,
Some times, i get this error from errors users... and i don't know how a fix
i'm sure the problem is in ContentChooser.
thanks.


B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
    at myworldapp.wow.com.ajustes._cc_result(ajustes.java:1174)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.phone.Phone$ContentChooser$1.ResultArrived(Phone.java:843)
    at anywheresoftware.b4a.BA$4.run(BA.java:513)
    at anywheresoftware.b4a.BA.setActivityPaused(BA.java:398)
    at myworldapp.wow.com.ajustes$ResumeMessage.run(ajustes.java:313)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:234)
    at android.app.ActivityThread.main(ActivityThread.java:5526)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 

DonManfred

Expert
Licensed User
Longtime User
without seeing the code used noone can help i guess
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
without seeing the code used noone can help i guess


B4X:
    Sub Activity_PermissionResult (Permission As String, Result As Boolean)
        Log(Permission & ": " & Result)
    End Sub
    Sub enviar_imagen

        If rp.Check(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)=False Then
            rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
            Return
        End If

       cc.Initialize("cc")
       cc.Show("image/*", "Choose image")
    End Sub

    Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
        Log("CCresult success:" & Success & " dir:" & Dir & " filename:" & FileName)
        If FileName.Contains("content://com.google.android.apps.photos") Or FileName.Contains("content://com.google.android.apps.docs.storage") Then
            Msgbox(t.t("No puede usar Fotos desde Google Idrive"),t.t("Info"))
            Return         
        End If
     
        File.Delete(codigo.DirDefaultExternal,"foto.jpg")
        If codigo.Nz(FileName,"")="" Then Return
        If Success=True Then
            Dim normalizedFile As String = codigo.GetPathFromContentResult(FileName)
            If normalizedFile= "" Then
                Msgbox(t.t("Imagen no compatible"),t.t("Info"))
                Return         
            End If
            If normalizedFile.Contains("http") Then
                'carga imagen
                job5.Initialize(Me)
                job5.jobbitmap(normalizedFile)     
                Return
            Else
                If codigo.copytryimage(Dir, FileName, codigo.DirDefaultExternal,"foto.jpg") Then
                    If File.Exists(codigo.DirDefaultExternal,"foto.jpg") Then
                        cropimage.callback=Me
                        'cropimage.bmp = LoadBitmap(codigo.DirDefaultExternal,"foto.jpg")
                        StartActivity(cropimage)
                        Return
                    End If
                End If
                If codigo.copytryimage("", normalizedFile, codigo.DirDefaultExternal,"foto.jpg") Then
                    If File.Exists(codigo.DirDefaultExternal,"foto.jpg") Then
                        cropimage.callback=Me
                        'cropimage.bmp = LoadBitmap(codigo.DirDefaultExternal,"foto.jpg")
                        StartActivity(cropimage)
                        Return
                    End If
                End If
            End If
        End If
    End Sub

B4X:
Sub GetPathFromContentResult(UriString As String) As String
    Log(">>> uristring:" & UriString)
    If UriString.StartsWith("/") Then Return UriString 'If the user used a file manager to choose the image
    Dim Cursor1 As Cursor
    Dim Uri1 As Uri
    Dim Proj() As String = Array As String("_data")
    Dim cr As ContentResolver
    cr.Initialize("")
    If UriString.StartsWith("content://com.android.providers.media.documents") Then
        Dim i As Int = UriString.IndexOf("%3A")
        Dim id As String = UriString.SubString(i + 3)
        Uri1.Parse("content://media/external/images/media")
        Cursor1 = cr.Query(Uri1, Proj, "_id = ?", Array As String(id), "")
    Else
        Uri1.Parse(UriString)
        Cursor1 = cr.Query(Uri1, Proj, "", Null, "")
    End If

    If Cursor1.IsInitialized Then
        Cursor1.Position = 0
        Dim res As String
        res = Cursor1.GetString("_data")
        Cursor1.Close
        Return res
    Else
        Return ""     
    End If
End Sub

Sub copytryimage(fromdir As String, fromfilename As String, todir As String, tofilename As String) As Boolean
    Try
        File.Copy(fromdir,fromfilename,todir,tofilename)
        Return True
    Catch
        Log("imagen no compatible")
        Log(LastException)
        Return False
    End Try
End Sub
 
Upvote 0
Top