-2

I have the following set-up

public class MainActivity extends AppCompatActivity implements LocationListener {    

GeoPoint pointTarget;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {

    pointTarget.setLatitude(51.4245);
    pointTarget.setLongitude(3.1455);

    }
}

This throws Attempt to invoke virtual method 'void org.osmdroid.util.GeoPoint.setLatitude(double)' on a null object reference at pointTarget.setLatitude(51.4245);

The two arguments are doubles, so that can't be the problem. pointTarget has also been instantiated. Can anyone please tell me what is wrong?

Jonathan
  • 63
  • 6

1 Answers1

0

Thank you for referring to "What is a NullPointerException, and how do I fix it?". I have now instantiated as private GeoPoint pointTarget = new GeoPoint(0.0,0.0);, which solved the problem. Perhaps I should switch to Kotlin, which apparently has no NullPointerExceptions.

Jonathan
  • 63
  • 6