Android : Null Pointer Exception due to Activity during Android Testing

on Sunday, March 22, 2015


I have a static database variable, dbVar, within MainActivity that is accessed throughout the entire application. When I attempt to perform unit tests on a UdpListener class that accesses dbVar, I get a NullPointerException. This makes sense, I suppose, because MainActivity is never created. I've read that I can test specific activities, but that seems like a poor fix in this situation because I'm not testing MainActivity, I'm testing UdpListener.


Partial Trace:



W/System.err﹕ java.lang.NullPointerException W/System.err﹕ at Comm.UDPListener.handleData(UDPListener.java:473)



Advice?


0 comments:

Post a Comment