Android Question Need to get Bmp from content URI

Steini1980

Active Member
Licensed User
Longtime User
Could someone help me implementing this Java code in my B4A Project:

B4X:
InputStream istr = contentResolver.openInputStream(uri);
BufferedInputStream buf_istr = new BufferedInputStream(istr, 8192);
Bitmap bm = BitmapFactory.decodeStream(buf_istr);

B4A ContentResolver doesn't supports the method openInputStream(uri)
And the ContentProvider doesn't results TableData, it results the Bitmap directly.
 

Steini1980

Active Member
Licensed User
Longtime User
On development device it works fine, but on Customer device I got java.lang.NullPointerException.
Does the customer needs anything to Install to get access on anywheresoftware.b4a.objects?
 
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
B4X:
Try
  LongVal = getImageIdByFilename(Main.dbProjektposten.GetString("Dateiname"))
  If LongVal <> -1 Then 
  url = "content://de.dirkfarin.imagemeterpro/image/anno/" & LongVal 
  File.Delete(File.DirDefaultExternal, Main.dbProjektposten.GetString("Dateiname"))
  Dim jo As JavaObject
  jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File")
  Dim In As InputStream = File.OpenInput(jo.GetField("ContentDir"), url)
  Dim bmp As Bitmap
  bmp.Initialize2(In)
  In.Close
  Dim out As OutputStream
  out = File.OpenOutput(File.DirDefaultExternal, Main.dbProjektposten.GetString("Dateiname"),False)
  bmp.WriteToStream(out,80,"JPEG")
  out.Close
  MemoAddLine("Aufmaßdatei "& Main.dbProjektposten.GetString("Dateiname") & " holen!")
  DateilisteJPG.Add(Main.dbProjektposten.GetString("Dateiname"))
  End If
Catch
  MemoAddLine("Export fehlgeschlagen: " & Main.dbProjektposten.GetString("Dateiname"))
  MsgBox(LastException.Message,"ERROR")
End Try

This is the affected source code, the LastException.Message returns just java.lang.NullPointerException.

Is it possible to get a more detailed ErrorMsg, e.g. to find out which code line is affected?
It's not possible to debug the Application, the error appears just at one customer device.
The Customer uses the same device and same Android, App and ImageMeter Version.

P.S.: Now I have added additional Check if In.isInitialised and write it to the Memo if not. But before delivering next release I will try anything to fix this Bug or locate the Bug if the Error isn't fixed. Is it also possible to read the "LOG" such like debugging but without active debugger?
 
Last edited:
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
Unfortunately I have no access to the customers device, so I can't Use debugging to find out the what's wrong.
The only way is to deliver a new release and waiting for response.

In case of an error currently I receive an E-Mail containiing App and Androcd Version, the Memo content and my Application sqlite Datebase.
Which information is also important?
 
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
Is it possible to read the permissions of the content provider?
content://de.dirkfarin.imagemeterpro/image/anno/

To open and Import Data into Imagemeter via Intent is possible.
But it seems the device has may be no permissons to receive data from ImageMeter?

On my own development device I checked with ContentProviderExplorer and got the following Information:

Authority: de.dirkfarin.imagemeterpro
Name: de.dirkfarin.imagemeter.lib.IMContentProvider
Package: de.dirkfarin.imagemeterpro
Process: de.dirkfarin.imagemeterpro
Read permission: NOT REQUIRED
Write permission: NOT REQUIRED

due to the fact that I think it's not caused by the permissions.
 
Last edited:
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
Thank you, erel. But if I run without Try/Catch the Customer gets the same error as Error Message, but also without further details in the Message, just:

java.lang.NullPointerException
Continue: YES|NO


How can I get further details? Is it possible to get the call stack oder read a part of the LogCat from Application (but I have no directly access to the device and customer has no root access.

I checked seperatly if In.isInitialised and it seems initialised:
B4X:
Dim In As InputStream = File.OpenInput(jo.GetField("ContentDir"), url)
If In.IsInitialized = False Then
  MemoAddLine("Inputstream nicht initialisiert: "& LongVal)
End If

Result:
Imagemeter Export fehlgeschlagen: V54262.o.1.jpg
java.lang.NullPointerException
Imagemeter Export fehlgeschlagen: V54262.o.2.jpg
java.lang.NullPointerException
Imagemeter Export fehlgeschlagen: V54262.o.3.jpg
java.lang.NullPointerException

There's no "Inputstream nicht initialisiert..." in the Resultmemo!
 
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
I have wrote Test Application contains Button1 and ImageView1 without Try-Catch Block:
B4X:
Sub Button1_Click
  Dim url As String
  Dim LongVal As Long
  Dim dialog As InputDialog
  dialog.InputType = dialog.INPUT_TYPE_NUMBERS
  dialog.Show("ImageMeter Image ID","Eingabe","OK","","",Null)
  If dialog.Response = DialogResponse.POSITIVE Then

      LongVal = dialog.Input
      If LongVal <> -1 Then   
        url = "content://de.dirkfarin.imagemeterpro/image/anno/" & LongVal
        File.Delete(File.DirDefaultExternal, "test_"& LongVal &".jpg")
        Dim jo As JavaObject
        jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File")
        Dim In As InputStream = File.OpenInput(jo.GetField("ContentDir"), url)
        Dim bmp As Bitmap
        bmp.Initialize2(In)
        In.Close
        Dim out As OutputStream
        out = File.OpenOutput(File.DirDefaultExternal, "test_"& LongVal &".jpg",False)
        bmp.WriteToStream(out,80,"JPEG")
        out.Close
        ImageView1.Bitmap = LoadBitmap(File.DirDefaultExternal,"test_"& LongVal &".jpg")
      End If
  End If
End Sub

But it breaks just with ErrorMessage as described above: java.lang.NullPointerException

On Development Device with same Hardware/Android Version it runs accurate.
Any ideas how to find out which part causes the failure?

Even if I give a wrong LongValue as ImageID I get back a DummyImage "Cannot load image" from Imagemeter.
 
Last edited:
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
I have not all informations, in case of an exception I got only the last ErrorMessage, but not the Call Stack from LogCat as seen in the Debugger.

Now I have created this nasty Code in a Demo App to find out where it hang up:
B4X:
        Label1.Text = "url = ""content://de.dirkfarin.imagemeterpro/image/anno/"" & LongVal"
        url = "content://de.dirkfarin.imagemeterpro/image/anno/" & LongVal   
        Label1.Text = "File.Delete(File.DirDefaultExternal, ""test_""& LongVal &"".jpg"")"
        File.Delete(File.DirDefaultExternal, "test_"& LongVal &".jpg")
        Label1.Text = "Dim jo As JavaObject"
        Dim jo As JavaObject
        Label1.Text = "jo.InitializeStatic(""anywheresoftware.b4a.objects.streams.File"")"
        jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File")
        Label1.Text = "Dim In As InputStream = File.OpenInput(jo.GetField(""ContentDir""), url)"
        Dim In As InputStream = File.OpenInput(jo.GetField("ContentDir"), url)
        Label1.Text = "Dim bmp As Bitmap"
        Dim bmp As Bitmap
        Label1.Text = "bmp.Initialize2(In)"
        bmp.Initialize2(In)
        Label1.Text = "In.Close"
        In.Close
        Label1.Text = "Dim out As OutputStream"
        Dim out As OutputStream
        Label1.Text = "out = File.OpenOutput(File.DirDefaultExternal, ""test_""& LongVal &"".jpg"",False)"
        out = File.OpenOutput(File.DirDefaultExternal, "test_"& LongVal &".jpg",False)
        Label1.Text = "bmp.WriteToStream(out,80,""JPEG"")"
        bmp.WriteToStream(out,80,"JPEG")
        Label1.Text = "out.Close"
        out.Close
        Label1.Text = "ImageView1.Bitmap = LoadBitmap(File.DirDefaultExternal,""test_""& LongVal &"".jpg"")"
        ImageView1.Bitmap = LoadBitmap(File.DirDefaultExternal,"test_"& LongVal &".jpg")
        Label1.Text = "FINISH!!!"

So I can see on which line the Exception is thrown, but if there's a better solution, I would built this in my Main App.
In case of an Exception, the Customer should sent the ErrorMessage including the Call Stack and further informations.
 
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
Now I have located the Java.Lang.NullPointerException on Customers device:

B4X:
Dim In As InputStream = File.OpenInput(jo.GetField("ContentDir"), url)

This Line causes the Exception, but why does it returns Null?
The Data is available on ImageMeter App.

Could someone help me?
 
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
No, thats my problem.. How can I get the stack trace? It's the device of my customer, it's not possible to use a debugger.
Is it possible to get the stack trace without running debugger? May be to read the logs and send via E-Mail?

But if you read the Source Code, url should always have a Value, it's just a string variable.
I'm sure it's JO or File.OpenInput which returns Null.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…