Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8293443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:49:48+00:00 2026-06-08T13:49:48+00:00

I am trying to learn how to location services and I got Null Pointer

  • 0

I am trying to learn how to location services and I got Null Pointer Exception when I tried to mark the my location on the map. Kindly help me remove this exception.

LogCat –

07-27 00:02:08.169: E/AndroidRuntime(304): FATAL EXCEPTION: main
07-27 00:02:08.169: E/AndroidRuntime(304): java.lang.NullPointerException
07-27 00:02:08.169: E/AndroidRuntime(304):  at com.google.android.maps.PixelConverter.toPixels(PixelConverter.java:71)
07-27 00:02:08.169: E/AndroidRuntime(304):  at com.google.android.maps.PixelConverter.toPixels(PixelConverter.java:61)
07-27 00:02:08.169: E/AndroidRuntime(304):  at com.sanjay.map.Map$MyLocationOverlay.draw(Map.java:116)
07-27 00:02:08.169: E/AndroidRuntime(304):  at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
07-27 00:02:08.169: E/AndroidRuntime(304):  at com.google.android.maps.MapView.onDraw(MapView.java:494)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.View.draw(View.java:6740)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.View.draw(View.java:6743)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.View.draw(View.java:6743)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-27 00:02:08.169: E/AndroidRuntime(304):  at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1842)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewRoot.draw(ViewRoot.java:1407)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.os.Looper.loop(Looper.java:123)
07-27 00:02:08.169: E/AndroidRuntime(304):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-27 00:02:08.169: E/AndroidRuntime(304):  at java.lang.reflect.Method.invokeNative(Native Method)
07-27 00:02:08.169: E/AndroidRuntime(304):  at java.lang.reflect.Method.invoke(Method.java:521)
07-27 00:02:08.169: E/AndroidRuntime(304):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-27 00:02:08.169: E/AndroidRuntime(304):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-27 00:02:08.169: E/AndroidRuntime(304):  at dalvik.system.NativeStart.main(Native Method)

Activity –

package com.sanjay.map;

import java.util.List;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;  
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class Map extends MapActivity {


MapController mapController;
MapView mapview;
 GeoPoint p=null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mapview = (MapView)findViewById(R.id.mapview);
    mapview.setBuiltInZoomControls(true);
    mapController = mapview.getController();
    mapController.setZoom(16);

    LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);

    LocationListener locationListener = new LocationListener() {

        private TextView locationDetails;

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLocationChanged(Location location) {
            makeUseOfNewLocation(location);
            //Toast.makeText(getApplicationContext(), "New Locationdd", Toast.LENGTH_LONG).show();

        }

        private void makeUseOfNewLocation(Location location) {


            double lon = (double) (location.getLongitude() * 1E6);
            double lat = (double) (location.getLatitude() * 1E6);

            int lontitue = (int)lon;
            int latitute = (int)lat;

            Toast.makeText(getApplicationContext(), "New Lontitue = "+ lontitue +"\n New Latitute = "+ latitute, Toast.LENGTH_LONG).show();
            locationDetails = (TextView)findViewById(R.id.textViewMap);
            locationDetails.setText("New Lontitue = "+ lontitue +"\n New Latitute = "+ latitute);

            GeoPoint geopoint = new GeoPoint(latitute, lontitue);
            mapController.animateTo(geopoint);

            MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
            List<Overlay> list = mapview.getOverlays();
            list.add(myLocationOverlay);


            //mapview.invalidate();
        }
    };

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,locationListener);
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}


public class MyLocationOverlay extends com.google.android.maps.Overlay {

@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
    Paint paint = new Paint();

    super.draw(canvas, mapView, shadow);
    // Converts lat/lng-Point to OUR coordinates on the screen.
    Point myScreenCoords = new Point();
    mapView.getProjection().toPixels(p, myScreenCoords);

    paint.setStrokeWidth(1);
    paint.setARGB(255, 255, 255, 255);
    paint.setStyle(Paint.Style.STROKE);

    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);

    canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
    canvas.drawText("You are here!", myScreenCoords.x, myScreenCoords.y, paint);
    return true;
}
}
}

Manifest –

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sanjay.map"
android:versionCode="1"
android:versionName="1.0" >

 <uses-permission android:name="android.permission.INTERNET" /> 
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 



<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <uses-library android:name="com.google.android.maps" />

    <activity
        android:name=".Map"
        android:label="@string/title_activity_map" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Layout –

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">


<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Waiting for location..."
android:id="@+id/textViewMap"/>




 <com.google.android.maps.MapView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/mapview"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:clickable="true"
  android:apiKey="/*My_KEY*/">


</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:49:50+00:00Added an answer on June 8, 2026 at 1:49 pm

    Your GeoPoint called p that you create at the top of the class is null. You never set it to something else. So you are effectively calling toPixels(null, myScreenCoords);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn pointer math better I wrote this code. The intention was to
Trying to learn a bit about PDO and is going through this tutorial .
trying to learn and practice arrays but I have a problem with this small
I'm trying learn Python (3 to be more specific) and I'm getting this error:
I'm still trying to learn SQL as of this writing, so I'm a bit
I'm trying learn more about RavenDB and at the moment to focus on how
I am trying learn the use of lambda expressions and hence still struggling to
Trying to learn Sencha Touch 2 and I can't seem to find out how
Trying to learn about php's arrays today. I have a set of arrays like
Trying to learn MVP pattern with C#... Does anyone know of any particularly good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.