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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:58:39+00:00 2026-06-04T12:58:39+00:00

I am trying to develop an application which has a button, which on clicking

  • 0

I am trying to develop an application which has a button, which on clicking should lead me to my current location in the map.
My main confusion is the OnClick Listener and the Map events. Where can i possibly go wrong?

Here is my code:-

package geopoint.ns;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
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;


public class GeoPointActivity extends MapActivity {

MapView mapView; 
MapController mc;
GeoPoint p;
TextView tvlat,tvlong;

protected LocationManager locationManager;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds
Button button;

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

    mapView = (MapView) findViewById(R.id.mapView);
    mapView.setBuiltInZoomControls(true);
    //mapView.displayZoomControls(true);
    mapView.setStreetView(false);
    mapView.setSatellite(false);

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

    locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 
            MINIMUM_TIME_BETWEEN_UPDATES, 
            MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
            new MyLocationListener()
    );

    tvlat = (TextView) findViewById(R.layout.main);
    tvlong = (TextView) findViewById(R.layout.main);
    mc = mapView.getController();
    addListenerOnButton();

}

public void addListenerOnButton() {
    button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getLoc();
        }
    });
}

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

class MapOverlay extends com.google.android.maps.Overlay implements OnClickListener
{
    @Override
    public boolean draw(Canvas canvas, MapView mapView, 
    boolean shadow, long when) 
    {
        super.draw(canvas, mapView, shadow);                   

        //---translate the GeoPoint to screen pixels---
        Point screenPts = new Point();
        mapView.getProjection().toPixels(p, screenPts);

        return true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
         //---when user lifts his finger---
        if (event.getAction() == 1) {                
            GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(),(int) event.getY());

            Geocoder geoCoder = new Geocoder(
                    getBaseContext(), Locale.getDefault());

            try 
            {
                List<Address> addresses = geoCoder.getFromLocation(
                    p.getLatitudeE6()/1E6, 
                    p.getLongitudeE6()/1E6, 1);

                String add = "";
                if (addresses.size() > 0) 
                {
                    for (int i=0; i<addresses.get(0).getMaxAddressLineIndex(); 
                         i++)
                       add += addresses.get(0).getAddressLine(i) + "\n";
                }

                Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
            }
            catch (IOException e) {                
                e.printStackTrace();
            }
            return true;
            //Toast.makeText(getBaseContext(), p.getLatitudeE6() / 1E6 + "," +p.getLongitudeE6() /1E6 ,Toast.LENGTH_SHORT).show();
        }
        else
            return false;
    }

    @Override
    public void onClick(View arg0) {
            getLoc();
        }
}

protected void getLoc () {
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    double lat = location.getLatitude();
    double lng = location.getLongitude();

    p = new GeoPoint(
        (int) (lat * 1E6), 
        (int) (lng * 1E6)); 
    mc.animateTo(p);
    mc.setZoom(17); 
}

 public class MyLocationListener implements LocationListener
 {
     @Override
     public void onLocationChanged(Location loc)
     {
     loc.getLatitude();
     loc.getLongitude();
     String Text = "My current location is: " +
     "Latitud = " + loc.getLatitude() +
     "Longitud = " + loc.getLongitude();
     Toast.makeText( getApplicationContext(),
     Text,
     Toast.LENGTH_SHORT).show();

     tvlat.setText(""+loc.getLatitude());
     tvlong.setText(""+loc.getLongitude());

     this.gpsCurrentLocation();
     }

     public void gpsCurrentLocation()
     {
     String coordinates[] = {""+tvlat.getText(), ""+tvlong.getText()};

     double lat = Double.parseDouble(coordinates[0]);
     double lng = Double.parseDouble(coordinates[1]);

     GeoPoint p = new GeoPoint(
     (int) (lat * 1E6),
     (int) (lng * 1E6));

     mc.animateTo(p);
     mc.setZoom(7);

     mapView.invalidate();

     }

     @Override
     public void onProviderDisabled(String provider)
     {
         Toast.makeText( getApplicationContext(),
         "Gps Disabled",
         Toast.LENGTH_SHORT ).show();
     }

     @Override
     public void onProviderEnabled(String provider)
     {
         Toast.makeText( getApplicationContext(),
         "Gps Enabled",
         Toast.LENGTH_SHORT).show();
     }

     @Override
     public void onStatusChanged(String provider, int status, Bundle extras)
     {

     }

 }

}

In the manifest file I have all the required permissions for GPS (ACCESS_FINE_LOCATION, ACCESS_MOCK_LOCATION & ACCESS_COARSE_LOCATION) and Internet.

My stack trace:-

    05-18 16:26:50.946: W/dalvikvm(381): Unable to resolve superclass of Lgeopoint/ns/GeoPointActivity; (22)
    05-18 16:26:51.026: W/dalvikvm(381): Link of class 'Lgeopoint/ns/GeoPointActivity;' failed
    05-18 16:26:51.066: D/AndroidRuntime(381): Shutting down VM
    05-18 16:26:51.066: W/dalvikvm(381): threadid=1: thread exiting with uncaught exception (group=0x40015560)
    05-18 16:26:51.206: E/AndroidRuntime(381): FATAL EXCEPTION: main
    05-18 16:26:51.206: E/AndroidRuntime(381): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{geopoint.ns/geopoint.ns.GeoPointActivity}: java.lang.ClassNotFoundException: geopoint.ns.GeoPointActivity in loader dalvik.system.PathClassLoader[/data/app/geopoint.ns-2.apk]
    05-18 16:26:51.206: E/AndroidRuntime(381):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at android.os.Handler.dispatchMessage(Handler.java:99)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at android.os.Looper.loop(Looper.java:130)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at android.app.ActivityThread.main(ActivityThread.java:3683)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at java.lang.reflect.Method.invokeNative(Native Method)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at java.lang.reflect.Method.invoke(Method.java:507)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at dalvik.system.NativeStart.main(Native Method)
    05-18 16:26:51.206: E/AndroidRuntime(381): Caused by: java.lang.ClassNotFoundException: geopoint.ns.GeoPointActivity in loader dalvik.system.PathClassLoader[/data/app/geopoint.ns-2.apk]
    05-18 16:26:51.206: E/AndroidRuntime(381):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    05-18 16:26:51.206: E/AndroidRuntime(381):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
    05-18 16:26:51.206: E/AndroidRuntime(381):  ... 11 more
    05-18 16:26:53.815: I/Process(381): Sending signal. PID: 381 SIG: 9

Is it that I am doing any logical mistake(s)?

UPDATE (AndroidManifest.xml):

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

        <uses-sdk android:minSdkVersion="10" />
        <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"/>

        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <activity
                android:name=".GeoPointActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

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

    </manifest>

Layout xml file: http://pastebin.com/q176i5d2

  • 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-04T12:58:40+00:00Added an answer on June 4, 2026 at 12:58 pm

    You didn’t add Google Maps library to your project inside your manifest,

    add this code under the Application Tag

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

    And make sure your project target SDK is Google API, not the normal SDK.

    Good Luck..

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

Sidebar

Related Questions

I am trying to develop a mobile application, which should run on all smartphones,
I am trying to develop a mobile application which can interact with a MOSS
I am trying to develop a Facebook application which shows me all the content
I am trying to develop a web application for which I need to capture
I am new to programming. I am trying to develop an application in which
I currently develop a server application which has to receive serialized data from clients,
I'm trying to develop a new application based on the standard Utility template, which
I am trying to develop an enterprise application which needs to list all the
I am trying to develop an application which needs to download and install other
I am currently trying to develop an application which uses Skype API to call

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.