Android Question java.lang.NullPointerException

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I keep seeing this message in a debug session and cannot figure out what is causing it.

Is there a easy way to determine where this happening?

Sometimes the debugger points me to this line:

Code: Copy
	If FirstTime Then
	   mFirstTime = True
	   
	   mUsePinPosition = 0                       '<---------------- Points to this line
	   
       mGPS.Initialize("GPS")	

       mGPSCourseEntry = -1
	   mGPSCourseHole  = -1
	   
	   mGPSCourseList.Initialize
	   mGPSCourse.Initialize
	   
	   mGPSParser.Initialize
	End If

But that line is defined in my process_globals as
Code: Copy
	Private mUsePinPosition                      As Int

Any Help

BobVal
 
Is it definitely that line in the code? As you've got an 'If FirstTime' check which precedes it and this could be what is causing you an issue, if you use the variable later on but haven't assigned a value.. as it isn't the 'FirstTime'..
 
Upvote 0
Yes, but there is always a FirstTime, I should have included the code above it.

Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
	
    Activity.LoadLayout("sPlayerScoring")
	Activity.Title = "Player Scoring"

	If FirstTime Then

Also this is a Int so even if I do not assign it a value, it should not give me a Null Pointer.

But in any case just to be sure I did a
Code: Copy
Private mUsePinPosition   as   Int  =  0

and am still have that Null Pointer. I believe it is somewhere else and just happens to be sometimes pointing there.

BobVal
 
Upvote 0
If you don't assign it a value it will be null. If you want it to always have a value you will need to assign it a value when it gets defined. :)

You always have a Firsttime, but if it isn't the first time it will be false.. and won't execute that code.
 
Upvote 0
thats legal, as is mine, but I think the OP's version is not and the assignement is simply ignored
 
Upvote 0
Move your assignment to
Sub Process_Globals()

Then it can be accessed anywhere
 
Upvote 0
Interesting questions about the assignments. If I cannot do my assignments that way then I have a lot of code to change because I do that all the time all over the place and to my knowledge have never had a problem.
Hopefull Erel will answer if
Code: Copy
Private mSomeVariable as Int = 0
is proper.
I do a lot of
Code: Copy
private mSomeVariable as Boolean = True
or
Code: Copy
private mSomeVarialbe as Boolean = False
and always have had them set right
 
Upvote 0
Well I figured out where this was happening:
Code: Copy
 DBCursor.GetString(DEFINE_DB_FieldTags_ImportantDates)
In the database I am using someone allowed this field to be Null and I assign it to a string variable that did not test for Null (sure wish allowing a Null field in a DB meant an Empty string "" for string types) but this line was inside a Try / Catch
and the catch part
Code: Copy
        Catch
                'Log(LastException.Message)
      End Try
was just eating up the Exception. Oh well that's what happens when you use OPC (Other peoples code). I guess I will have to look at all this code instead of just using it.

Thanks for the help guys.
 
Upvote 0
Back
Top