Android Question java.lang.RuntimeException: Object should first be initialized (Bitmap)

Almora

Well-Known Member
Licensed User
Longtime User
  • CurrentFrame As Bitmap [read only]
    Returns current videoframe which can be used for screenshot.

B4X:
Expand Collapse Copy
Sub Globals
    Dim bitmap As Bitmap
    Private ImageView1 As ImageView
End Sub

...............

Sub Button4_Click

    ImageView1.Bitmap=vvvit5.CurrentFrame
  
    bitmap=ImageView1.Bitmap

        Dim Out As OutputStream
        Out = File.OpenOutput(File.DirRootExternal, "test1.png", False)
        bitmap.WriteToStream(Out, 90, "PNG")
        Out.Close

End Sub

video_button4_click (java line: 455)
java.lang.RuntimeException: Object should first be initialized (Bitmap).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.WriteToStream(CanvasWrapper.java:693)
at vitamio.test.test.video._button4_click(video.java:455)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4633)
at android.view.View$PerformClick.run(View.java:19274)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Object should first be initialized (Bitmap).

hi..
this code does not work in android 4.1, 4.2, 4.4. But android works at 6, 7, 8.

I am getting such an error. I've tried a lot of methods. I could not. how can i solve the problem. Thank you.
 
Last edited:
What is in vvvit5.CurrentFrame? This may behave differently in 4.1, etc. and may not contain what you think (such as null instead of a bitmap).

Edit: I need to read better. You posted what current frame is. I still stand by my logic that you may need to make sure it contains what you expect it to contain under 4.1, etc.
 
Upvote 0
What is in vvvit5.CurrentFrame? This may behave differently in 4.1, etc. and may not contain what you think (such as null instead of a bitmap).

vvvit5.CurrentFrame= video screencapture Method in my vitamio library.

I want to capture the screen image and display the imageview.

I could send a project to those who have the vitamio library.
 
Upvote 0
vvvit5.CurrentFrame= video screencapture Method in my vitamio library.
But it seems to return null at this point.....
 
Upvote 0
Have you checked if the value returned from the CurrentFrame method is null or not. You can see that in the debugger.
Do you see any other errors in the unfiltered logs?
Did you try it in release mode?

As I wrote in our conversation, I need to get hold of a device which is running 4.1, 4.2, 4.4 so I can test at my end.
Also as I mentioned, here is a user that gets the same error but only on certain devices although I don't know if this is related to your problem...
 
Upvote 0
If vvvit5.CurrentFrame is not null, then try this:

B4X:
Expand Collapse Copy
'*******************************
'change your bitmap declaration as follows
'(don't know if it is important or not)
Dim bitmap1 As Bitmap
'*******************************

Sub Button4_Click
'in your Button4_Click event, initialize the Bitmap
bitmap1.Initialize3(vvvit5.CurrentFrame)
ImageView2.Bitmap=bitmap1
'.......

Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "test1.png", False)
bitmap1.WriteToStream(Out, 90, "PNG")
Out.Close

'......

End Sub
 
Upvote 0
I tested it on Android 4.4.2. I got the following errors. It works on Android 6.
thanks..
 

Attachments

  • PicsArt_11-30-01.58.23.jpg
    PicsArt_11-30-01.58.23.jpg
    121.8 KB · Views: 396
  • log.txt
    log.txt
    1.7 KB · Views: 369
Upvote 0
Then I guess vvvit5.CurrentFrame is null. Did you check it?
 
Upvote 0
I will check again when I can borrow an old device from a friend of mine and then let you know if I can reproduce it.
 
Upvote 0
I think this problem is related to android 4.

I tested it with the Betterimageview library. Android 4 did not work. But he worked on android 6.
Android 4 has a black screen.


B4X:
Expand Collapse Copy
 BetterImageView1.BackgroundBitmap=vvvit5.CurrentFrame
 
Upvote 0
On the phones/Android editions that fail, see what the log results are:

B4X:
Expand Collapse Copy
Sub Globals
    Dim bitmap As Bitmap

    ' Just because I don't like variable names that are the same as an class name
    Dim capturedBitmap as Bitmap

    Private ImageView1 As ImageView
End Sub

...............

Sub Button4_Click
    'capturedBitmap is a global variable
    capturedBitmap=vvvit5.CurrentFrame

    If capturedBitmap = Null Then
        ' This is what we mean by checking to see if the bitmap is null
        Log("Bitmap is null")
    Else If capturedBitmap.IsInitialized = False Then
        ' Bitmap may not be null, but un-initialized
        Log("Bitmap is not initialized")
    Else
        ' The bitmap should be ok here, since we have a non-null, initialized bitmap
        Log("Processing returned bitmap")
        ImageView1.Bitmap=capturedBitmap
       
        Dim Out As OutputStream
        Out = File.OpenOutput(File.DirRootExternal, "test1.png", False)
        capturedBitmap.WriteToStream(Out, 90, "PNG")
        Out.Close
    End If
End Sub
 
Upvote 0
Finally I got a chance to test it on a 4.4.2 device (samsung 3 Neo) and it works fine. I tried your test-project you sent me by PM and I only modified the code as mentioned in post6 in this thread and as I said, it worked fine. It might work with the original code as well but I did not try this.

Try the code suggested by @OliverA and see if "vvvit5.CurrentFrame" returns null or not.

Do you have further information as to the devices which are not working such as make (Samsung, HTC etc)? By the way, you did try on real devices, right (and not emulators)?
 
Upvote 0
I tried code @OliverA.

Günlükçü þuna baðlandý: 24beaed0
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main~i:*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (video) Create, isFirst = true **
** Activity (video) Resume **
vvvit5_Prepared
Bitmap is not initialized
video_button4_click (java line: 487)
java.lang.RuntimeException: Object should first be initialized (Bitmap).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at vitamio.test.test.video._button4_click(video.java:487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4633)
at android.view.View$PerformClick.run(View.java:19274)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Object should first be initialized (Bitmap).


android 4.4.2
samsun galaxy s4 mini [GT I9190]
no root.
 
Upvote 0
Back
Top