durka/HallMonitor

NullPointerException on local machine

Closed this issue · 4 comments

I tried to modify the code a bit on my machine but I get a NullPointerException in the Functions class because defaultActivity is null. I can't find the line where to set it before starting the Activity. I tried to run the code while the Activity is not initialised. Where do you do that?

Can I have some more detail about where the error occurred? Post a stack trace if you can. defaultActivity should be set to the singleton instance of DefaultActivity while the activity is visible (yeah, it's kind of a hack and needs to be refactored, but such is life).

My problem is that the service calls Functions.proximity where close_cover is called. There you use defaultActivity.onScreen. But the Activity is not showen before and so the object is null. So you have to set it before but I can't find where.

I do not think that a stacktrace is usefull here. I only do what I described above and there is only the NullPointerException with the lines from the code.

If you are talking about Functions.java line 116, that is checking DefaultActivity.on_screen, not defaultActivity.on_screen. Those are quite different because DefaultActivity is the class so it is referencing the static variable on_screen. If that's what you changed then it would explain the NPE.

Oh yes sorry you are right. Was my mistake works fine now. Thank you.