Only In Jelly Bean 4.1 Error

rtesluk

Member
Licensed User
Longtime User
Jul 3 2012
06:00 Hours

I get this error only in version 4.1

Camera1_Ready - java.lang.NullPointerException

Here is the entire code of the activity

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   Dim Panel1 As Panel
   Dim btnTakePicture As Button
   Dim ButtonExit As Button
   Dim LabelFileLocation As Label
   
   Dim Camera1 As Camera
End Sub
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("TakePic.bal")
   Activity.Color = Colors.RGB(CodeModule.PanR,CodeModule.PanG,CodeModule.PanB)
   
   LabelFileLocation.Text = "#" 
   LabelFileLocation.Color = Colors.RGB(CodeModule.LblR,CodeModule.LblG,CodeModule.LblB)  
   LabelFileLocation.TextColor = Colors.RGB(CodeModule.TxtR,CodeModule.TxtG,CodeModule.TxtB)
   LabelFileLocation.TextSize = CodeModule.TCARndTextSize
   If CodeModule.FancyFormatOnOff2 = True Then
      LabelFileLocation.Background = CodeModule.GD(Colors.RGB(CodeModule.LblR,CodeModule.LblG,CodeModule.LblB),Colors.RGB(CodeModule.TxtR,CodeModule.TxtG,CodeModule.TxtB),CodeModule.TCVCurrentRndCornerValue,CodeModule.sPattern)
   End If
End Sub
Sub Activity_Resume
   btnTakePicture.Enabled = False
   Camera1.Initialize(Panel1, "Camera1")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
   Camera1.Release
End Sub
Sub LabelFileLocation_Click
   LabelFileLocation.Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
   LabelFileLocation.TextColor = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
End Sub
Sub Camera1_Ready (Success As Boolean)
   Try
      If Success Then
         Camera1.StartPreview
         btnTakePicture.Enabled = True
      Else
         ToastMessageShow("Cannot open camera.", True)
      End If
   Catch
      Msgbox(LastException.Message,"Camera1_Ready") 
   End Try
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
   Camera1.StartPreview
   Dim Out As OutputStream
   Dim CurrentDate, CurrentTime As Long, sDT As String  
   'Get No. of Ticks of Current Date CurrentDate Long = Primitive Variable
   CurrentDate = DateTime.DateParse(DateTime.Date(DateTime.Now))    
   'Get No. of Ticks of Current Time CurrentTime Long = Primitive Variable
   CurrentTime = DateTime.TimeParse(DateTime.Time(DateTime.Now))    
   sDT = ""
   sDT = sDT & DateTime.GetYear(CurrentDate)
   sDT = sDT & NumberFormat(DateTime.GetMonth(CurrentDate),2,0)
   sDT = sDT & NumberFormat(DateTime.GetDayOfMonth(CurrentDate),2,0)
   sDT = sDT & "_"
   sDT = sDT & NumberFormat(DateTime.GetHour(CurrentTime),2,0)
   sDT = sDT & NumberFormat(DateTime.GetMinute(CurrentTime),2,0)
   sDT = sDT & NumberFormat(DateTime.GetSecond(CurrentTime),2,0)
   sDT = sDT & ".jpg" 
   Try
      If File.IsDirectory (File.DirRootExternal,CodeModule.sImgAudDir) = False Then
         File.MakeDir(File.DirRootExternal,CodeModule.sImgAudDir)
      End If
      Out = File.OpenOutput(File.DirRootExternal & "/" & CodeModule.sImgAudDir, sDT, False)
      Out.WriteBytes(Data, 0, Data.Length)
      Out.Close
      LabelFileLocation.Text = File.DirRootExternal & "/" & CodeModule.sImgAudDir & "/" & sDT
   Catch
      Msgbox(LastException.Message,"PictureTaken") 
   End Try
   ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal & "/" & CodeModule.sImgAudDir, sDT), True)
   btnTakePicture.Enabled = True
End Sub
Sub btnTakePicture_Click
   btnTakePicture.Enabled = False
   Camera1.TakePicture
End Sub
Sub ButtonExit_Click
   Activity.Finish 
   StartActivity(Options)   
End Sub

Ray Tesluk :sign0104:
 

Theera

Well-Known Member
Licensed User
Longtime User

Try delete "Camera1.Initialize(Panel1, "Camera1") " I think I had ever myself
 
Upvote 0

rtesluk

Member
Licensed User
Longtime User
Yes, I am testing on the emulator

Yes, I am.

I tried another app using the camera library and another app using the advanced camera library which work on all the other versions of Android.

These two other apps gave the same error message.

Ray Tesluk
 
Upvote 0

rtesluk

Member
Licensed User
Longtime User
Try delete "Camera1.Initialize(Panel1, "Camera1") " I think I had ever myself

I deleted the initialization and I ended up with a disabled button - did not work

ray
 
Upvote 0

rtesluk

Member
Licensed User
Longtime User
Deleted AVD JellyBean 4.1 Created Android_4_1

I deleted the AVD JellyBean and created another AVD Android_4_1 with level 16.

I get the same error on the emulator with all three of my apps which use the camera library or the advanced camera library.

I checked to see if these three apps created a problem with levela 8, 10, 14 and 15 and they worked OK.

I guess I will just wait until Google updates level 16 in the near future. After all, JellyBean is a new version of Android. Maybe, there are a few glitches in the initial release.

I don't think there is a device out there that uses version 4.1 level 16 yet, but they will come and maybe I can load my apps unto one of them.

Thanks for the help.

Ray
 
Upvote 0

rtesluk

Member
Licensed User
Longtime User
Erel The Great

Erel

Thanks a bunch for getting this info to me.

Sooo, what are our options for developing with the camera and advanced camera libraries for the future?

I liked that camera feature within my app because I had control where to place the image files and edit them afterwards.

Maybe, Google will see 'the light' and add the camera function to Jelly Bean like all of the rest of the former versions.

Thanks again - I will no longer fuss about this problem. Perhaps, I will find a a way to use the built in Android camera from within my apps.

Ray :sign0060:
 
Upvote 0

rtesluk

Member
Licensed User
Longtime User
Version 4.1 Level 16 Emulator

Do you mean on the emulator?

Have you tried adding the camera to the emulator emulated hardware:

Yes, I added back camera as emulator (not web or not none) to the emulator device Android_4_1 and I got the same error message.

I also tried front camera (without back camera which I deleted from emulator's hardware) as emulator and got the same error message.

Maybe, I will just leave it alone for awhile because I might be missing a step somewhere along the line.

Thanks again, for helping me. Cheers Ray
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…