Force close in Map

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Force close in Map

Postby ganimal78 » Wed Jun 15, 2011 4:20 pm

Hello, i'm having a problem with my app. I have a tabbed view and on one of the tabs i have a map view. when I start the app for the first time and go to my map tab, the tab will start and show my GPS location and the Map. But if i close the app then start it again i get a forced close if i hit the map tab. also if i restart my phone the map tab will work until i close the app, then it will force close the app. Please help thanks.

Here is my code for my map activity
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class FishingGpsMap extends MapActivity implements LocationListener {
  2.         static final String tag = "FishingGpsMap";
  3.         LocationManager locationManager;
  4.         MapController mapController;
  5.         String provider;
  6.         MyPositionOverlay positionOverlay;
  7.         @Override
  8.         public void onCreate(Bundle savedInstanceState){
  9.                 super.onCreate(savedInstanceState);
  10.                 setContentView(R.layout.fishing_map);
  11.                
  12.                 locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
  13.                 Criteria criteria = new Criteria();
  14.         criteria.setAccuracy(Criteria.ACCURACY_FINE);
  15.         criteria.setAltitudeRequired(false);
  16.         criteria.setBearingRequired(false);
  17.         criteria.setCostAllowed(true);
  18.         criteria.setPowerRequirement(Criteria.POWER_LOW);
  19.        
  20.         provider = locationManager.getBestProvider(criteria, true);
  21.         Location location = locationManager.getLastKnownLocation(provider);
  22.        
  23.         updateWithNewLocation(location);
  24.        
  25.         MapView MyMapView = (MapView)findViewById(R.id.MyMapVeiw);
  26.         MyMapView.setBuiltInZoomControls(true);
  27.         mapController = MyMapView.getController();
  28.         positionOverlay = new MyPositionOverlay();
  29.             List<Overlay> overlay = MyMapView.getOverlays();
  30.             overlay.add(positionOverlay);
  31.         }
  32.         @Override
  33.         protected void onResume()
  34.         {
  35.                 locationManager.requestLocationUpdates(provider, 15000, 10, this);
  36.                 super.onResume();
  37.         }
  38.        
  39.         @Override
  40.         protected void onPause()
  41.         {
  42.                 locationManager.removeUpdates(this);
  43.                 super.onPause();
  44.         }
  45.         private void updateWithNewLocation(Location location)
  46.     {
  47.            String latLongString;
  48.          
  49.            
  50.         if(location != null)
  51.         {
  52.                 //update my location maker
  53.                 positionOverlay.setlocation(location);
  54.                 //update the map location
  55.                 Double geoLat = location.getLatitude()*1E6;
  56.                 Double geoLong = location.getLongitude()*1E6;
  57.                 GeoPoint point = new GeoPoint(geoLat.intValue(), geoLong.intValue());
  58.                 double lat = location.getLatitude();
  59.                 double lng = location.getLongitude();
  60.                
  61.                 latLongString = "\nLat: "+lat+"\nLong: "+lng;
  62.                    
  63.                 mapController.animateTo(point);
  64.     }
  65.         else
  66.         {
  67.                 latLongString = "No location found";
  68.         }
  69.         ((GlobalVaribles)getApplication()).setLatLng(latLongString);
  70. }
  71.         @Override
  72.         protected void onStop() {
  73.                 finish();
  74.                 super.onStop();
  75.         }
  76.  
  77.         @Override
  78.         protected boolean isRouteDisplayed() {
  79.                 // TODO Auto-generated method stub
  80.                 return false;
  81.         }
  82.  
  83.         @Override
  84.         public void onLocationChanged(Location location) {
  85.                 // TODO Auto-generated method stub
  86.                 updateWithNewLocation(location);
  87.         }
  88.  
  89.         @Override
  90.         public void onProviderDisabled(String provider) {
  91.                 // TODO Auto-generated method stub
  92.                 /* this is called if/when the GPS is disabled in settings */
  93.                 Log.v(tag, "Disabled");
  94.  
  95.                 /* bring up the GPS settings */
  96.                 Intent intent = new Intent(
  97.                                 android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  98.                 startActivity(intent);
  99.         }
  100.  
  101.         @Override
  102.         public void onProviderEnabled(String provider) {
  103.                 // TODO Auto-generated method stub
  104.                
  105.         }
  106.  
  107.         @Override
  108.         public void onStatusChanged(String provider, int status, Bundle extras) {
  109.                        
  110.                
  111.         }
  112.        
  113.         @Override
  114.            public boolean onCreateOptionsMenu(Menu menu) {
  115.                MenuInflater inflater = getMenuInflater();
  116.                inflater.inflate(R.menu.map_menu, menu);
  117.                return true;
  118.            }
  119.            @Override
  120.            public boolean onOptionsItemSelected(MenuItem item) {
  121.                // Handle item selection
  122.                switch (item.getItemId()) {
  123.                case R.id.ViewLocation:
  124.                 Context context = getApplicationContext();
  125.                         String text = ((GlobalVaribles)getApplication()).getlatLng();
  126.                         int duration = Toast.LENGTH_SHORT;
  127.                        
  128.                         Toast toast = Toast.makeText(context, text, duration);
  129.                         toast.show();
  130.                    return true;
  131.                case R.id.SaveFdata:
  132.                    Intent i;
  133.                                 i = new Intent(FishingGpsMap.this, addDetails.class);
  134.                                 startActivity(i);
  135.                    return true;
  136.                case R.id.quit:
  137.                    finish();
  138.                    return true;
  139.                default:
  140.                    return super.onOptionsItemSelected(item);
  141.                }
  142.            }
  143.  
  144. }
  145.  
Parsed in 0.047 seconds, using GeSHi 1.0.8.4
ganimal78
Freshman
Freshman
 
Posts: 4
Joined: Wed Feb 02, 2011 6:33 pm

Top

Re: Force close in Map

Postby AndroidLab » Mon Jun 20, 2011 10:12 am

Read more in your LogCat to see what's happen.
AndroidLab
Freshman
Freshman
 
Posts: 3
Joined: Thu Jun 09, 2011 12:16 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests