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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:49:25+00:00 2026-05-27T07:49:25+00:00

When i change the gps location of the phone the program just crashes, it

  • 0

When i change the gps location of the phone the program just crashes, it don’t seem to find the google maps id (find by id)
This is my code:

package Maps.GeoLocation.Google;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

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


public class MapsGeoLocationActivity extends MapActivity {
    MapController mControl;
    GeoPoint GeoP;
    MapView mapV;

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

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        LocationListener ll = new mylocationlistener();
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);

    }

    public void maps(double pLati, double pLongi)
    {
        mapV = (MapView) findViewById(R.id.mapView);
        mapV.displayZoomControls(true);
        mapV.setBuiltInZoomControls(true);
        GeoP = new GeoPoint ((int) (pLati *1E6), (int) (pLongi *1E6));
        mControl = mapV.getController();
        mControl.animateTo(GeoP);
        mControl.setZoom(13); 
    }
    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}

class mylocationlistener implements LocationListener {
    double pLong;
    double pLat;

    @Override
    public void onLocationChanged(Location location) {
            MapsGeoLocationActivity ff = new MapsGeoLocationActivity();
            pLong = location.getLongitude();
            pLat = location.getLatitude();
            //textLat.setText(Double.toString(pLat));
            //textLong.setText(Double.toString(pLong));
            ff.maps(pLat, pLong);

    }

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

    }

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

    }

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

    }

}

Main.xml (This can’t be wrong, but in case you guys ask)

<?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"
    >
<com.google.android.maps.MapView
                 android:id="@+id/mapView"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:enabled="true"
                 android:clickable="true"
                 android:apiKey="apikey"
                 />
</LinearLayout>

LogCat:
http://img195.imageshack.us/img195/5655/16325616.png

  • 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-27T07:49:26+00:00Added an answer on May 27, 2026 at 7:49 am

    Ok, here is the thing: Firstly, try to think how you want to structure your program.

    You are registering a location listener in the onCreate method of an activity. Then in the onLocationChanged method what you do is to create a new instance of the same activity, thus resulting in onCreate being called again. So you are registering the same listener again, and when the location changes again and again and so on. I am not exactly sure where the NullPointer comes from but I believe it is something to do with this infinite cycles that you have created.

    This is not how you should do it. The best way is to have your LocationListener work as a service (i.e. independent of the activity which “hosts” the MapView), so in the onLocationChanged method you will have to send an intent to the activity which will update the view and the location on the map.

    Hope this makes sense.

    PS: I believe you are new to Android development, so make sure you PERFECTLY understand this http://developer.android.com/guide/topics/fundamentals.html before starting to code. Also: http://developer.android.com/guide/topics/fundamentals/activities.html and this: http://developer.android.com/guide/topics/fundamentals/services.html

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

Sidebar

Related Questions

This is the code i use to find my current location but it is
Im trying to change this code to do reverse geocoding as well. Coordinates work
I would like to get location of user, so I have this code: LocationManager
I want to make GPS app and I'm starting with this code which is
My app should find the current location using GPS , Cellular network or WiFi
friends, i am using following code to get GPS location it is causing two
Here is the code to find the current location, but nothing shows on the
How change int value in block, I have this : __block long long size
Edit: I'm rewriting this question because I apparently wasn't clear. Sometimes the GPS service
Hai am trying to get the gps location using BroadCast Receiver.its working fine,But i

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.