Force close on map activity start

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

Force close on map activity start

Postby xaire » Wed Jan 20, 2010 5:48 am

Everytime I try running a mapview, I get a force close. I am not sure. I have tried several different examples, and all cause the program to force close on the emulator. The most recent attempt I have is from a tutorial found in the tutorial section.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Location extends Activity {
  3.  
  4.  
  5.  
  6.         private LocationManager locationManager=null;;
  7.  
  8.         private LocationListener locationListener=null;;
  9.  
  10.  
  11.  
  12.         private MapView mapView1=null;
  13.  
  14.         private MapController mapController=null;
  15.  
  16.  
  17.  
  18.         /** Called when the activity is first created. */
  19.  
  20.        
  21.  
  22.         LinearLayout linearLayout;
  23.  
  24.         MapView mapView;
  25.  
  26.         ZoomControls mZoom;
  27.  
  28.        
  29.  
  30.         protected boolean isRouteDisplayed() {
  31.  
  32.             return false;
  33.  
  34.             }  
  35.  
  36.        
  37.  
  38.        
  39.  
  40.         @Override
  41.  
  42.         public void onCreate(Bundle icicle) {
  43.  
  44.                 super.onCreate(icicle);
  45.  
  46.                
  47.  
  48.                 linearLayout = (LinearLayout) findViewById(R.id.zoomview);
  49.  
  50.                 mapView1 = (MapView) findViewById(R.id.mapview);
  51.  
  52.                 mZoom = (ZoomControls) mapView1.getZoomControls();
  53.  
  54.                
  55.  
  56.                
  57.  
  58.                 linearLayout.addView(mZoom);
  59.  
  60.                
  61.  
  62.                
  63.  
  64.                 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  65.  
  66.                                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
  67.  
  68.                 requestWindowFeature(Window.FEATURE_NO_TITLE);
  69.  
  70.                 //setContentView(R.layout.gps);
  71.  
  72.                 //---use the LocationManager class to obtain GPS locations---
  73.  
  74.                 locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  75.  
  76.  
  77.  
  78.                 locationListener = new MyLocationListener();
  79.  
  80.  
  81.  
  82.                 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
  83.  
  84.                                 locationListener);
  85.  
  86.  
  87.  
  88.                 //mapView = (MapView) findViewById(R.id.mapview1);
  89.  
  90.                 mapController = mapView1.getController();
  91.  
  92.         }
  93.  
  94.                 private class MyLocationListener implements LocationListener {
  95.  
  96.                         public void onLocationChanged(Location loc) {
  97.  
  98.                                 if (loc != null) {
  99.  
  100.                                         Toast.makeText(
  101.  
  102.                                                         getBaseContext(),
  103.  
  104.                                                         "Location changed : Lat: " + loc.getLatitude()
  105.  
  106.                                                                         + " Lng: " + loc.getLongitude(),
  107.  
  108.                                                         Toast.LENGTH_LONG).show();
  109.  
  110.  
  111.  
  112.                                         GeoPoint p = new GeoPoint((int) (loc.getLatitude() * 1E6),
  113.  
  114.                                                         (int) (loc.getLongitude() * 1E6));
  115.  
  116.                                         mapController.animateTo(p);
  117.  
  118.                                         mapController.setZoom(12);
  119.  
  120.                                         mapView1.invalidate();
  121.  
  122.                                 }
  123.  
  124.                         }
  125.  
  126.  
  127.  
  128.                         public void onProviderDisabled(String provider) {
  129.  
  130.                                 // TODO Auto-generated method stub
  131.  
  132.                         }
  133.  
  134.  
  135.  
  136.                         public void onProviderEnabled(String provider) {
  137.  
  138.                                 // TODO Auto-generated method stub
  139.  
  140.                         }
  141.  
  142.  
  143.  
  144.                         public void onStatusChanged(String provider, int status, Bundle extras) {
  145.  
  146.                                 // TODO Auto-generated method stub
  147.  
  148.                         }
  149.  
  150.                 }
  151.  
  152.         }
  153.  
  154.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:layout_width="fill_parent"
  7.  
  8.    android:layout_height="fill_parent">
  9.  
  10.      <com.google.android.maps.MapView
  11.  
  12.        android:id="@+id/mapView"
  13.  
  14.        android:layout_width="fill_parent"
  15.  
  16.        android:layout_height="fill_parent"
  17.  
  18.        android:clickable="true"
  19.  
  20.        android:apiKey="ABQIAAAAqQKMdD9OLeimkIL0wHajjxTN27yOuGByoT5-5yeF29y281bBZBQTCHN2VO_vbhwhTy3CSQ9qFi6uGg"
  21.  
  22.    />
  23.  
  24.  <LinearLayout android:id="@+id/zoom"
  25.  
  26.        android:layout_width="wrap_content"
  27.  
  28.        android:layout_height="wrap_content"
  29.  
  30.        android:layout_alignParentBottom="true"
  31.  
  32.        android:layout_centerHorizontal="true"
  33.  
  34.        android:enabled="true"
  35.  
  36.        android:clickable="true"
  37.  
  38.        />
  39.  
  40. </RelativeLayout>
  41.  
  42.  
  43.  
  44.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


Can someone help explain what is wrong? I had logcat working earlier this morning, but now it doesn't seem to be showing anything, so I'm sorry I can't provide you with what error it was giving me.
xaire
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 1:56 am
Location: Texas

Top

Postby Draffodx » Thu Jan 21, 2010 11:54 am

The logccat will show whats happening when the app crashes, get it back logging and post the error thats happening, it will be a lot easier to pin point the problem then
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby xaire » Thu Jan 21, 2010 1:58 pm

Alright, after working with it a little while, logcat started working again. This is what was shown around the time of the force close.

Code: Select all
01-21 06:45:31.847: ERROR/ActivityThread(643): Failed to find provider info for com.google.settings
01-21 06:45:31.897: ERROR/ActivityThread(643): Failed to find provider info for com.google.settings
01-21 06:45:34.018: ERROR/MediaPlayerService(542): Couldn't open fd for content://settings/system/notification_sound
01-21 06:45:34.027: ERROR/MediaPlayer(563): Unable to to create media player
01-21 06:45:26.024: ERROR/ActivityThread(609): Failed to find provider info for android.server.checkin
01-21 06:45:27.293: ERROR/ActivityThread(609): Failed to find provider info for android.server.checkin
01-21 06:45:27.403: ERROR/ActivityThread(609): Failed to find provider info for android.server.checkin
01-21 06:45:38.893: ERROR/AndroidRuntime(720): Uncaught handler: thread main exiting due to uncaught exception
01-21 06:45:38.933: ERROR/AndroidRuntime(720): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.WOT/com.test.WOT.Location}: java.lang.NullPointerException
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at android.os.Looper.loop(Looper.java:123)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at android.app.ActivityThread.main(ActivityThread.java:3948)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at java.lang.reflect.Method.invokeNative(Native Method)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at java.lang.reflect.Method.invoke(Method.java:521)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at dalvik.system.NativeStart.main(Native Method)
01-21 06:45:38.933: ERROR/AndroidRuntime(720): Caused by: java.lang.NullPointerException
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at com.test.WOT.Location.onCreate(Location.java:58)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
01-21 06:45:38.933: ERROR/AndroidRuntime(720):     ... 11 more



Thank you!
xaire
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 1:56 am
Location: Texas

Postby Draffodx » Fri Jan 22, 2010 10:12 am

can you post what line 58 is in Location.java?
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby xaire » Fri Jan 22, 2010 2:21 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. mZoom = (ZoomControls) mapView1.getZoomControls();
  3.  
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


In Eclipse, this line has "getZoomControls()" striked out.

I have tried commenting it out to see if that would fix any issue, but it didn't.
xaire
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 1:56 am
Location: Texas

Postby Draffodx » Fri Jan 22, 2010 4:57 pm

xaire wrote:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mZoom = (ZoomControls) mapView1.getZoomControls();
  2.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


In Eclipse, this line has "getZoomControls()" striked out.

I have tried commenting it out to see if that would fix any issue, but it didn't.


Thats simply because getZoomControls() is depracated so that wouldn't be the problem.

You should change it to this anyway:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. WebView.getSettings().setBuiltInZoomControls(true);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


The problem is at line 58 in Location.java, go to that class, then click navigate from the menu bar>go to line and type in 58, post whatever this line is
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Postby xaire » Fri Jan 22, 2010 7:37 pm

Sorry. I meant to say that the zoomcontrol line is line 58.
xaire
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 1:56 am
Location: Texas

Postby xaire » Sat Jan 23, 2010 5:55 am

Ok. Just had a chance to look at the app and do what you said about using "go to line". Line 58 is actually the line above what I thought.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. mapView1 = (MapView) findViewById(R.id.mapview);
  3.  
  4.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
xaire
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 1:56 am
Location: Texas

Postby Draffodx » Mon Jan 25, 2010 10:59 am

xaire wrote:Ok. Just had a chance to look at the app and do what you said about using "go to line". Line 58 is actually the line above what I thought.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mapView1 = (MapView) findViewById(R.id.mapview);
  2.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Should mapview not have a big V?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mapView1 = (MapView) findViewById(R.id.mapView);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby padde » Mon Jan 25, 2010 11:41 am

The api-key looks wrong to me.. mine is just 39 chars long.. yours is huge.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby xaire » Tue Jan 26, 2010 2:28 am

That is the API key that I got from google. If it was wrong, would that cause the app to force close or just not work?

I changed the "V" like Draffodx suggested, and it seems to be having a new issue on line 67 now. That line is
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. requestWindowFeature(Window.FEATURE_NO_TITLE);
  3.  
  4.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
xaire
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 1:56 am
Location: Texas

Postby Draffodx » Tue Jan 26, 2010 11:26 am

What error is it giving you on that line?

A wrong map api key wont force close an application anyway, it will still run but the maps will not display
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby glmason » Tue Jan 26, 2010 6:25 pm

Hi, I'm new at this but I think the Location class has to extend MapActivity in stead of Activity...

Cheers Larry

PS Is this where you got your key from:
http://code.google.com/android/maps-api-signup.html

I agree with one of the previous posts, the key does not look right.
glmason
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Jan 12, 2010 5:08 pm

Postby glmason » Tue Jan 26, 2010 10:04 pm

Hi again...

One more thing to check... did you put the following lines or at least one of them in the AndroidManifest.xml...?


<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

...after the </application> tag.

Larry
glmason
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Jan 12, 2010 5:08 pm

Postby xaire » Wed Jan 27, 2010 3:48 am

This is the what logcat shows

Code: Select all
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at android.os.Looper.loop(Looper.java:123)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at android.app.ActivityThread.main(ActivityThread.java:3948)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at java.lang.reflect.Method.invokeNative(Native Method)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at java.lang.reflect.Method.invoke(Method.java:521)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at dalvik.system.NativeStart.main(Native Method)
01-26 20:39:09.509: ERROR/AndroidRuntime(755): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:281)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at android.app.Activity.requestWindowFeature(Activity.java:2556)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at com.test.WOT.Location.onCreate(Location.java:67)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
01-26 20:39:09.509: ERROR/AndroidRuntime(755):     ... 11 more


I did not get my API key there...thank you for the correct link.

And yes, I do have the proper permissions. I will attach the permissions that I currently have to make sure I'm not missing one.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <uses-permission android:name="android.permission.INTERNET"/>
  3.  
  4. <uses-permission android:name="android.permission.ACCESS_GPS" />
  5.  
  6. <uses-permission android:name="android.permission.ACCESS_LOCATION" />
  7.  
  8. <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  9.  
  10. <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
  11.  
  12. <uses-permission android:name="android.permission.ACCESS_CELL_ID" />
  13.  
  14. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  15.  
  16. <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
xaire
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 1:56 am
Location: Texas

Top
Next

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 1 guest