I'm trying to obtain the user's location, and this seems to be giving me trouble.
When I call distanceBetween()
to see test if it's working I get a NullPointerException at getApplicationContext()
. Is there something I am not doing?
Here is the Stacktrace:
java.lang.NullPointerException at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109) at com.ayy.zz.DistanceFinder.onCreate(DistanceFinder.java:38) at com.ayy.zz.DistanceFinder.distanceBetween(DistanceFinder.java:82) at com.ayy.zz.DistanceFinderTests.testSomething(DistanceFinderTests.java:14) at java.lang.reflect.Method.invokeNative(Native Method) at student.TestCase.runBare(TestCase.java:108) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
TestSomething is simply initializing a DistanceFinder and calling the distanceBetween method:
public double distanceBetween()
{
onCreate();
return dining1.distanceTo(dining2);
}