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 6865317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:01:43+00:00 2026-05-27T03:01:43+00:00

I am trying to implement the map showing the current location with the path.

  • 0

I am trying to implement the map showing the current location with the path. while running it crashes.

I checked the manifest too.. but I dont know what the error is..

PLease help me, I am new bee in android..

here is my code:

MapActivity.java

package com.GoogleMaps;

import java.util.List;

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;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class MapsActivity extends MapActivity {
/** Called when the activity is first created. */

 private MapView mapView;
 private LocationManager lm;
 private LocationListener ll;
 private MapController mc;
 GeoPoint p = null;
 Drawable defaultMarker = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView)findViewById(R.id.mapview);
    //show zoom in/out buttons
    mapView.setBuiltInZoomControls(true);
    //Standard view of the map(map/sat)
    mapView.setSatellite(false);
    //get controller of the map for zooming in/out
    mc = mapView.getController();
    // Zoom Level
    mc.setZoom(18); 

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

    lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    ll = new MyLocationListener();

    lm.requestLocationUpdates(
            LocationManager.GPS_PROVIDER,
            0,
            0,
            ll);

    //Get the current location in start-up
    GeoPoint initGeoPoint = new GeoPoint(
           (int)(lm.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLatitude()*1000000),
           (int)(lm.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLongitude()*1000000));
           mc.animateTo(initGeoPoint);
}

protected 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.ic_launcher);

            canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
            canvas.drawText("I am here...", myScreenCoords.x, myScreenCoords.y, paint);
            return true;
        }
    }

private class MyLocationListener implements LocationListener{

      public void onLocationChanged(Location argLocation) {
       // TODO Auto-generated method stub
       GeoPoint myGeoPoint = new GeoPoint((int)(argLocation.getLatitude()*1000000), (int)(argLocation.getLongitude()*1000000));

       Toast.makeText(getBaseContext(),
               "New location latitude [" +argLocation.getLatitude() +
               "] longitude [" + argLocation.getLongitude()+"]",
               Toast.LENGTH_SHORT).show();


       mc.animateTo(myGeoPoint);

      }

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

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

      public void onStatusChanged(String provider,
        int status, Bundle extras) {
       // TODO Auto-generated method stub
      }
     }    
protected boolean isRouteDisplayed() {
    return false;
}
}

main.xml:

<?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"
   > 
 <LinearLayout
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   >
    <TextView
     android:id="@+id/longitude"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:text="Longitude:"
  />
  <TextView
   android:id="@+id/latitude"
   android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:text="Latitude:"
  />
 </LinearLayout>
 <com.google.android.maps.MapView
  android:id="@+id/mapview"
  android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="false"
  android:apiKey="0dB02TjP-H_UqgsDpfxAhtsvGo5Z8cUJsTeHeDA"
 />
</LinearLayout>

Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.GoogleMaps"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library  android:required="true" android:name="com.google.android.maps"/>
        <activity
            android:label="@string/app_name"
            android:name=".MapsActivity" >
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
  <uses-library android:name="com.google.android.maps" />
   </application>
   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
   <uses-sdk android:minSdkVersion="8" />
</manifest>

logcat file:

11-29 03:26:49.620: D/AndroidRuntime(671): Shutting down VM
11-29 03:26:49.620: W/dalvikvm(671): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-29 03:26:49.640: E/AndroidRuntime(671): FATAL EXCEPTION: main
11-29 03:26:49.640: E/AndroidRuntime(671): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.GoogleMaps/com.GoogleMaps.MapsActivity}: java.lang.NullPointerException
11-29 03:26:49.640: E/AndroidRuntime(671):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-29 03:26:49.640: E/AndroidRuntime(671):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-29 03:26:49.640: E/AndroidRuntime(671):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-29 03:26:49.640: E/AndroidRuntime(671):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-29 03:26:49.640: E/AndroidRuntime(671):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-29 03:26:49.640: E/AndroidRuntime(671):  at android.os.Looper.loop(Looper.java:123)
11-29 03:26:49.640: E/AndroidRuntime(671):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-29 03:26:49.640: E/AndroidRuntime(671):  at java.lang.reflect.Method.invokeNative(Native Method)
11-29 03:26:49.640: E/AndroidRuntime(671):  at java.lang.reflect.Method.invoke(Method.java:521)
11-29 03:26:49.640: E/AndroidRuntime(671):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-29 03:26:49.640: E/AndroidRuntime(671):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-29 03:26:49.640: E/AndroidRuntime(671):  at dalvik.system.NativeStart.main(Native Method)
11-29 03:26:49.640: E/AndroidRuntime(671): Caused by: java.lang.NullPointerException
11-29 03:26:49.640: E/AndroidRuntime(671):  at com.GoogleMaps.MapsActivity.onCreate(MapsActivity.java:65)
11-29 03:26:49.640: E/AndroidRuntime(671):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-29 03:26:49.640: E/AndroidRuntime(671):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-29 03:26:49.640: E/AndroidRuntime(671):  ... 11 more
11-29 03:26:52.320: I/Process(671): Sending signal. PID: 671 SIG: 9
  • 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-05-27T03:01:44+00:00Added an answer on May 27, 2026 at 3:01 am

    You are getting a NullPointerException at line 65 of the MapsActivity class. Could you post that line all by itself?

    A possible culprit is that you do not check whether getLastLocation returns null, which is a possibility.

    Surround those lines with a null check

    //Get the current location in start-up, if it exists
    if (lm.getLastKnownLocation(LocationManager.GPS_PROVIDER) != null) {
        GeoPoint initGeoPoint = new GeoPoint(
            (int)(lm.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLatitude()*1000000),
            (int)(lm.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLongitude()*1000000));
         mc.animateTo(initGeoPoint);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement my own map overlay for osmdroid (but I assume
I am trying to implement google map api into one of my web page
I'm trying to implement an identity map using generics. I have an abstract class,
While trying to implement an MVC file upload example on Scott Hanselman's blog. I
I am trying to implement a search option in my google map using pincode...
I'm trying to implement an exponential moving average (EMA) on postgres, but as I
I am trying to implement my own provider for xml site map files. Because
I have been working on this for a while and am trying to implement
I'm trying to implement a default valued map , and I'd like filters, maps,
Goal: To render a google map using geolocation. I am trying to implement the

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.