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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:09:37+00:00 2026-06-01T15:09:37+00:00

I am simply trying to display a users location on a map, I am

  • 0

I am simply trying to display a users location on a map, I am very new to android development but I have basics in java.

Basically I am sending mock data from Eclipse (lang/long co-ords), as soon as this data is sent my application crashes with the following:

    04-07 21:07:52.252: E/AndroidRuntime(639): FATAL EXCEPTION: main
04-07 21:07:52.252: E/AndroidRuntime(639): java.lang.NullPointerException
04-07 21:07:52.252: E/AndroidRuntime(639):  at com.herghost.bmad.BMAD$1.onLocationChanged(BMAD.java:60)
04-07 21:07:52.252: E/AndroidRuntime(639):  at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:227)
04-07 21:07:52.252: E/AndroidRuntime(639):  at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:160)
04-07 21:07:52.252: E/AndroidRuntime(639):  at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:176)
04-07 21:07:52.252: E/AndroidRuntime(639):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-07 21:07:52.252: E/AndroidRuntime(639):  at android.os.Looper.loop(Looper.java:137)
04-07 21:07:52.252: E/AndroidRuntime(639):  at android.app.ActivityThread.main(ActivityThread.java:4424)
04-07 21:07:52.252: E/AndroidRuntime(639):  at java.lang.reflect.Method.invokeNative(Native Method)
04-07 21:07:52.252: E/AndroidRuntime(639):  at java.lang.reflect.Method.invoke(Method.java:511)
04-07 21:07:52.252: E/AndroidRuntime(639):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-07 21:07:52.252: E/AndroidRuntime(639):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-07 21:07:52.252: E/AndroidRuntime(639):  at dalvik.system.NativeStart.main(Native Method)

The code for my application is:

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class BMAD extends Activity {


    private LocationManager locmgr = null;
    private TextView mytext;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);



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

        final Button button = (Button)
        findViewById(R.id.launchmap);
        button.setOnClickListener(new Button.OnClickListener() 
        {
            public void onClick(View view) 
                {
                    try 
                        {
                            LocationManager address = locmgr;
                            Intent geoIntent = new Intent
                            (android.content.Intent.ACTION_VIEW,
                            Uri.parse("geo:0,0?q=" + address));
                            startActivity(geoIntent);
                        } 
                    catch (Exception e) 
                        {

                        }
                }


        });}
//Start a location listener
LocationListener onLocationChange=new LocationListener() {
    public void onLocationChanged(Location loc) {
        //sets and displays the lat/long when a location is provided
        String latlong = "Lat: " + loc.getLatitude() + " Long: " + loc.getLongitude();   
        mytext.setText(latlong);
    }

    public void onProviderDisabled(String provider) {
    // required for interface, not used
    }

    public void onProviderEnabled(String provider) {
    // required for interface, not used
    }

    public void onStatusChanged(String provider, int status,
    Bundle extras) {
    // required for interface, not used
    }
};

//pauses listener while app is inactive
@Override
public void onPause() {
    super.onPause();
    locmgr.removeUpdates(onLocationChange);
}

//reactivates listener when app is resumed
@Override
public void onResume() {
    super.onResume();
    locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,10000.0f,onLocationChange);
}
}

Can anyone lead me to what is causing this?

  • 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-01T15:09:38+00:00Added an answer on June 1, 2026 at 3:09 pm

    You don’t initialize mytext variable. It causes NPE on line 60 of your code mytext.setText(latlong);.

    You should do something like mytext = findViewById(R.id.mytext); in your onCreate() method.

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

Sidebar

Related Questions

hey, im new to android development and trying to make my first application. What
I am trying to use a Canvas to display objects that have world location
I'm very new to WPF and the EF, and I'm trying to display some
I am trying to write a very simple RSS channel which would display the
Ok, I'm very simply trying to take this example... http://jsfiddle.net/shanabus/HGF59/ and put it on
Here is my view. I am trying to simply display a table with the
I am trying to create an app that will obtain the users location via
I have been trying to integrate my very simple voice recorder app with the
I'm trying to display an alert message for the users in a catch block.
So basically I have been trying to insert columns into my third table from

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.