nullpointerexception

MichaelTJ

Member
Licensed User
Longtime User
Sub Button7_Click
StartActivity("CPF")
End Sub

the first time the above is executed it works just fine.... the second time it is executed it give the error

***
An error has occurred in sub:
cpf_globals(B4A line:575)
End Sub
java.langNullPointerException
Continue?
***
this is of course followed by Yes or No


the 575 line number displayed in the error msg is the "End Sub" of the "Button7_Click" subroutine

if you just say yes and continue the program behaves just fine but every time you use Button7 it does the same thing

used this program for months with no problems.... where do i put what line to kill this error message.... don't really care about the why of it much, just want it to go away

thank you
 

MichaelTJ

Member
Licensed User
Longtime User
** Activity (Main) Resume **
** Activity (Main) Pause, UserClosed = false **
java.lang.NullPointerException in red

again, first time into form "CPF" works just fine but when you leave the "CPF" form and then try to open it a second time you get this..... if you answer "Yes" the "CPF" form works just fine
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Seems like you're returning to the activity without recreating it. This way you may have non-intialized components, causing this error.
 
Upvote 0

MichaelTJ

Member
Licensed User
Longtime User
Here is a chunk of the code for the CPF module/form.... it is no different from code that appears in a dozen other module/forms.... have received advise to initialize, initialize WHAT?.... error message continues to point at "End Sub" line of calling form


Sub Globals

Dim EditText1 As EditText
Dim EditText2 As EditText
Dim EditText3 As EditText
Dim EditText4 As EditText
Dim EditText5 As EditText
Dim EditText6 As EditText
Dim EditText7 As EditText
Dim EditText8 As EditText

EditText1.Initialize("")
EditText2.Initialize("")
EditText3.Initialize("")
EditText4.Initialize("")
EditText5.Initialize("")
EditText6.Initialize("")
EditText7.Initialize("")
EditText8.Initialize("")

SQL1.Initialize(File.DirDefaultExternal, "DTrack.db", True)

Dim Button1 As Button
Dim Button2 As Button
Dim Button3 As Button
Dim Button4 As Button

End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("CPF")
Activity.Title = "CPF table entry and listing"

EditText1.text = ""

If EditText2.text = "" Then EditText2.text = "0"
If EditText3.text = "" Then EditText3.text = "0"
If EditText4.text = "" Then EditText4.text = "0"
If EditText5.text = "" Then EditText5.text = "0"

End Sub

Sub Activity_Resume

End Sub


been pushing things in and out and all around but no luck getting rid of the errors as described at the top..... the called and calling screen both function perfectly save for this popup error message
 
Upvote 0

MichaelTJ

Member
Licensed User
Longtime User
i have a number of forms that feed off the top form.... all behave perfectly except for this CPF from/module

on ANY other called form if i flip the device sideways it reorients without difficulty even though the lower part of the format may not be visible.... when flipped back it does this perfectly as well

when flipped sideways the CPF form responds with

***
An error has occurred in the sub:cpf_globals (B4A line: 56)
End Sub
java.lang.NullPointerException
Continue?
***

if you click on "Yes" to continue the CPF form is displayed correctly in the sideways orientation

the line number 56 "End Sub" above is the "End Sub" of the Globals sub
 
Upvote 0

MichaelTJ

Member
Licensed User
Longtime User
FOUND IT!!!!

for some unknown reason the
SQL1.Initialize(File.DirDefaultExternal, "DTrack.db", True)
line was located in the Globals rather than Process_Globals sub...

moving it to Process_Globals cured the problem.... have know idea why i put it in the wrong place just this one time single time and it seems really strange being as i tend to clone and then modify.....
 
Upvote 0
Top