Android Question "Attempt to get length of null array" on Camera Picture Sizes

Rob Bliss

Member
Licensed User
I haven't managed to replicate the error myself, however a user of mine has experienced it.

He's tried to load the camera, and then it crashed with: "java.lang.NullPointerException: Attempt to get length of null array" which was caused by the bottom line.
B4X:
Sub Camera1_Ready (Success As Boolean)
    If Success Then
        '           For TROUBLESHOOTING, check the resolution supported
        Dim pictureSizes() As CameraSize = camEx.GetSupportedPicturesSizes
        Dim previewSizes() As CameraSize = camEx.GetSupportedPreviewSizes

        Dim LowResolution As Int = pictureSizes.Length - 1

To me, it seems as though the picture sizes came back null, in which case how and why had Success not been set as false?

On theory of mine, which I can't prove, or understand why it would happen, is in the GetSupportedPictureSizes function (see below) it failed the initial fetch and got caught by the try clause.
B4X:
Public Sub GetSupportedPicturesSizes As CameraSize()
   Try
       r.target = parameters
       Dim list1 As List = r.RunMethod("getSupportedPictureSizes")
       Dim cs(list1.Size) As CameraSize
       For i = 0 To list1.Size - 1
           r.target = list1.get(i)
           cs(i).Width = r.GetField("width")
           cs(i).Height = r.GetField("height")
       Next
       Return cs
   Catch
       Log(LastException)
   End Try
End Sub


Has anyone seen this before, and/or think they might know what caused it??

Any help would be appreciated
 
Last edited:

Rob Bliss

Member
Licensed User
I think the function was crashing before it had chance to return the camera sizes, hence it would return null to the _ready function (solved that bit by returning an empty CameraSize object; it seems to hold together despite having to use 0x0 for preview and picture dimensions).

So if I'm right about that bit, I would like to know what might (theoretically) cause it to trigger the try/catch. It must've found a camera to use, else it wouldn't have gotten this far into the code and would've returned Success as False.
 
Upvote 0
Top