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

  • Home
  • SEARCH
  • 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 6831877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:47:23+00:00 2026-05-26T22:47:23+00:00

I am writing an application that retrieves coordinates from a webservice, then plots them

  • 0

I am writing an application that retrieves coordinates from a webservice, then plots them on a map together with my current location: I am able to write the code wich does not have any error but when i run it on the emulator it crashes….what could be the problem: Here is the code:

public abstract class MapActivity extends com.google.android.maps.MapActivity{

    // Instance attributes
    private MapView mapView = null;
    private MapController mc = null;
    private GeoPoint p = null;
    private LocationManager locationManager;
    private LocationListener locationListener;


@Override 
protected void onDestroy() {
    super.onDestroy();
}


public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    switch (keyCode) 
    {
        case KeyEvent.KEYCODE_3:
            mc.zoomIn();
            break;
        case KeyEvent.KEYCODE_1:
            mc.zoomOut();
            break;
    }
    return super.onKeyDown(keyCode, event);
}  


public void initMap(){

    // Get the main element
    mapView = (MapView) findViewById(R.id.mapView);
    mc  = mapView.getController();

    // Add a zoom
    mapView.setBuiltInZoomControls(true);

    mapView.displayZoomControls(true);

    // Initialize the zoom level
    mc = mapView.getController();

    mc.setZoom(17);

    //---Add a location marker---
    MapOverlay mapOverlay = new MapOverlay();
    List<Overlay> listOfOverlays = mapView.getOverlays();
    listOfOverlays.clear();
    listOfOverlays.add(mapOverlay);        

    mapView.invalidate();

}


public void drawElements(MapView mapView, Canvas canvas, String element){

    if (mapView == null){
        return;
    }
    try {

        // Get elements
        JSONObject elements = JSONfunctions.getJSONfromURL("http://10.0.2.2/android/rental.php");

        JSONArray results = elements.getJSONArray("rental");

        if (results != null && results.length() != 0){

                for (int i = 0; i < elements.length(); i++) {

                    JSONObject result = results.getJSONObject(i);
                     //---fetch the coordinates from the remote server------
                    double lat = Double.parseDouble((String) result.get("lat"));
                    double lon = Double.parseDouble((String) result.get("lon"));

                    //---translate the GeoPoint to screen pixels---
                    Point screenPts = new Point();
                    GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));
                    mapView.getProjection().toPixels(p, screenPts);

                    //---add the marker---
                    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.red);         
                    canvas.drawBitmap(bmp, screenPts.x-20, screenPts.y-40, null);    

                }
        }

    } catch (JSONException e) {
        Log.e(null,"JSONException error");
    }
}


/**
 * Re-center the icon on the map
 */
public void refreshMapLocation(){

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);    
    locationListener = new GPSLocationListener();

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

}

private class GPSLocationListener implements LocationListener 
{


    @Override
    public void onLocationChanged(Location location) {

        GeoPoint p = new GeoPoint(
                (int) (location.getLatitude() * 1E6), 
                (int) (location.getLongitude() * 1E6));

        // Animate the map on the point
        if (p != null && mc !=null){
            mc.animateTo(p);
        } else {
            Log.e(null,"Couldn't refresh location on the map");
        }

    }

    @Override
    public void onProviderDisabled(String provider) {

    }

    @Override
    public void onProviderEnabled(String provider) {

    }

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

    }
}

protected boolean isRouteDisplayed() {
    return false;
}

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

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

            //---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.blue);         
            canvas.drawBitmap(bmp, screenPts.x-10, screenPts.y-20, null);     
        }

        //drawElements(mapView,canvas,"Hospitals");

       return true;
    }

}
}

edit.** On looking at the error posted by Logcat this is what it has to say

11-20 09:10:31.931: I/Process(756): Sending signal. PID: 756 SIG: 9
11-20 09:39:57.001: D/dalvikvm(789): newInstance failed: p0 i0 [0 a1
11-20 09:39:57.001: D/AndroidRuntime(789): Shutting down VM
11-20 09:39:57.041: W/dalvikvm(789): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-20 09:39:57.091: E/AndroidRuntime(789): FATAL EXCEPTION: main
11-20 09:39:57.091: E/AndroidRuntime(789): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.jkuat.project/com.jkuat.project.MapActivity}: java.lang.InstantiationException: com.jkuat.project.MapActivity
11-20 09:39:57.091: E/AndroidRuntime(789):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-20 09:39:57.091: E/AndroidRuntime(789):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-20 09:39:57.091: E/AndroidRuntime(789):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-20 09:39:57.091: E/AndroidRuntime(789):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-20 09:39:57.091: E/AndroidRuntime(789):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 09:39:57.091: E/AndroidRuntime(789):  at android.os.Looper.loop(Looper.java:123)
11-20 09:39:57.091: E/AndroidRuntime(789):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-20 09:39:57.091: E/AndroidRuntime(789):  at java.lang.reflect.Method.invokeNative(Native Method)
11-20 09:39:57.091: E/AndroidRuntime(789):  at java.lang.reflect.Method.invoke(Method.java:521)
11-20 09:39:57.091: E/AndroidRuntime(789):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-20 09:39:57.091: E/AndroidRuntime(789):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-20 09:39:57.091: E/AndroidRuntime(789):  at dalvik.system.NativeStart.main(Native Method)
11-20 09:39:57.091: E/AndroidRuntime(789): Caused by: java.lang.InstantiationException: com.jkuat.project.MapActivity
11-20 09:39:57.091: E/AndroidRuntime(789):  at java.lang.Class.newInstanceImpl(Native Method)
11-20 09:39:57.091: E/AndroidRuntime(789):  at java.lang.Class.newInstance(Class.java:1429)
11-20 09:39:57.091: E/AndroidRuntime(789):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-20 09:39:57.091: E/AndroidRuntime(789):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
11-20 09:39:57.091: E/AndroidRuntime(789):  ... 11 more
  • 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-26T22:47:24+00:00Added an answer on May 26, 2026 at 10:47 pm

    this is happening because you declared your MapActivity class as Abstract. Since it’s abstract, the VM cannot instantiate it when you launch that activity. Remove the abstract keyword and this should be resolved.

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

Sidebar

Related Questions

I'm writing a Java desktop client application that retrieves data from a remote MySQL
I am writing an sms application that retrieves the messages from a MYSQL database
I'm writing a web application that constantly retrieves XML components from a database and
I'm writing a GUI application that regularly retrieves data through a web connection. Since
Im writing an application that supposed to send coordinates in an SMS, but I've
Hey guys, I am writing an application that retrieves the Group Names and access
I have a simple application that retrieves a dataset from the database and converts
I am writing a simple business app that retrieves data from a server for
I'm writing an application that pulls values out of an Excel spreadsheet and then
I am writing an application in C# that reads info from a .mdb file

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.