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

  • StalkerApp.zip
    56.2 KB · Views: 195

NJDude

Expert
Licensed User
Longtime User
The culprit is somewhere here:

B4X:
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.

B4X:
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

Nyptop

Active Member
Licensed User
Longtime User
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

Nyptop

Active Member
Licensed User
Longtime User
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

NJDude

Expert
Licensed User
Longtime User
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

Nyptop

Active Member
Licensed User
Longtime User
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

  • StalkerApp1.zip
    56.3 KB · Views: 176
Upvote 0

NJDude

Expert
Licensed User
Longtime User
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.
 
Upvote 0

Nyptop

Active Member
Licensed User
Longtime User
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

  • stalkerapp2.zip
    57.5 KB · Views: 159
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Well, it was failing because you forgot to add a few things, check the attached project and look at the "StalkScreen" activity, I made notes pointing out what you forgot.
 

Attachments

  • Stalker_FIXED.zip
    57.7 KB · Views: 190
Upvote 0
U

unba1300

Guest
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

NJDude

Expert
Licensed User
Longtime User
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

Nyptop

Active Member
Licensed User
Longtime User
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

NJDude

Expert
Licensed User
Longtime User
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

Nyptop

Active Member
Licensed User
Longtime User
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:

B4X:
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:

B4X:
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…