Null Pointer Exception

Nyptop

Active Member
Licensed User
Longtime User
I'm having problems with null pointer exceptions and getting confused. Could anyone help?

Thanks
 

Attachments

The culprit is somewhere here:

Code: Copy
Sub mainpanel_click

    Activity.LoadLayout("StalkScreen")

    For LoopStopper = 1 To 1

        camera1.Quality = C1Q
        timer1.Initialize ("Timer1" , Speed)
        timer1.Enabled = True
        camera1.TakePicture
        timer1.Enabled = True

    Next 

End Sub

First of all, I don't know why you are using a For...Next, second, you have a timer but do not have a Timer1_Tick routine.

It seems to me the camera part has a problem, if I comment the lines as shown below it seems to work, but you are not verifying if someone didn't select a file (tapping on the panel, then click on VIEW button and then the BACK button on the device) that also gives an error.

Code: Copy
Sub mainpanel_click

    Activity.LoadLayout("StalkScreen")

    'For LoopStopper = 1 To 1

        'camera1.Quality = C1Q
        timer1.Initialize ("Timer1" , Speed)
        timer1.Enabled = True
        'camera1.TakePicture
        'timer1.Enabled = True

    'Next 

End Sub

...

Sub Timer1_Tick 'You don't have this routine in your code.

    ToastMessageShow("Tick...", False)

End Sub

I hope that helps you out.
 
Last edited:
Upvote 0
Ok thanks, but I want the app to take a photo, wait the specified time and keep on taking photos until the user stops the process. How should I go about this?

Also, I believe the problem lay specifically with the setting of the camera quality, what was I doing wrong their?

Thanks for the help :)
 
Upvote 0
I'm still getting the issue of Null pointer exception. The issue no longer lies with the camera1.quality, it lies with the camera1.takepicture.

Thanks For the help and sorry about all the questions but I think I'm getting there.
 
Upvote 0
My sample uses the "official" camera library, what's the one you are using? but if you say you are having problems during TakePicture (NullException), reboot your phone, that should solve that problem.
 
Last edited:
Upvote 0
I have rebooted a couple of times and it is still not working :( I have also removed the quality function so that I can use the standard camera library but the problem persists. I have been playing around a lot with the code but that still hasn't worked. Attached is as far as I have gotten.
 

Attachments

Upvote 0
Thanks NJDude, I have changed it so as that there are different activities. however, the problem persists. I am still getting Null pointer exception. Would anyone minded testing the app as it stands on their device just so I know that where the problem lies (code or device) and if its not to much effort suggest a possible solution for me to work on? Thanks :)
 

Attachments

Upvote 0
Ok, by looking at your code I see a problem, if you want different layouts you have to either put them on different activities or use panels, that's the problem you are having.

Is it really necessary to use more than one activity or panels when using more than one layout? I've been using a Sub ('remove all views') each time just before loading a different layout. Is this not a good approach? Thanks.
 
Upvote 0
It's better because it allows you maintain and debug your app more efficiently, at least, that's my opinion. In this case, there is a timer updating a view, by removing it, it causes the app to fail.
 
Last edited:
Upvote 0
With the different activities I have a new problem: Say a Bitmap is saved in the 'settings' activity how could we access it from other activities?
 
Upvote 0
Variables can be accessed from any activity if they are define in Process_Globals.

Better check some documentation an samples using the search feature of this forum.
 
Last edited:
Upvote 0
Sorry, I miss-phrased my question but I have the answer now: thanks for the help :)

In the sub chooser_result the code is as follows:

Code: Copy
Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        bmp.Initialize(File.DirDefaultExternal, FileName)
    Else
        ToastMessageShow("No image selected", True)
    End If
End Sub

Then when I use 'bmp' the code is:

Code: Copy
Sub Activity_Create(FirstTime As Boolean)

        
      
        PictureCounter = 0
              If settings.bmp.IsInitialized Then
            Camera1.Quality = settings.Q
      Activity.LoadLayout("StalkScreen")
      activity.SetBackgroundImage (settings.bmp)
      stalkscreen.SetBackgroundImage (settings.bmp)
      Camera1.Initialize(StalkScreen, "Camera1")
            
            Timer1.Initialize ("Timer1", settings.timerinterval) 
      Timer1.Enabled = True
      Else
      Msgbox ("Please select an image" ,"")
      StartActivity ("settings")
    End If
            
End Sub

The image is not loading to the background though. Could you point me in the correct direction as to what to do.

Thanks again,

Neil
 
Upvote 0
Back
Top