Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy does my android app which uses GPS to find the current location encounters a crash, every time I run it? It shows a force close
    primarykey
    data
    text
    <p>I'.m developing this on Eclipse. My app aims at finding the current location using GPS, but when I run it on the emulator, it shows an unexpected force close. I have attached the main.xml, java file and manifest.xml.</p> <p><strong>Main file:</strong></p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" tools:context=".GooglemapsActivity" &gt; &lt;com.google.android.maps.MapView android:id="@+id/mapview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="0o6t2Gs5-C0eAHL2ZNbwvzu4pwsgX50HX2X8rKA" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>Java file:</strong></p> <pre><code>package com.example.mapgp; import android.location.Location; import android.location.LocationManager; import android.location.LocationListener; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.view.Menu; import com.example.mapgp.R; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import android.widget.Toast; public class Gmapwithgps extends MapActivity { public MapView mapView; public MapController mc; public MyLocationListener locl; public LocationManager manager; public class MyLocationListener implements LocationListener { public void onLocationChanged(Location loc) { loc.getLatitude(); loc.getLongitude(); String Text = "My current location is: " + "Lati = " + loc.getLatitude() + "Longi = " + loc.getLongitude(); Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show(); } @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) { } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_gmapwithgps); mapView = (MapView) findViewById(R.id.mapview1); mapView.setBuiltInZoomControls(true); mc = mapView.getController(); manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); locl = new MyLocationListener(); manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 35000, 10, this.locl); } protected boolean isRouteDisplayed() { return false; } public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_gmapwithgps, menu); return true; } </code></pre> <p>}</p> <p><strong>Manifest.xml file:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mapgp" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10" /&gt; &lt;uses-permission android:name="android.permission.INTERNET"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;uses-library android:name="com.google.android.maps"/&gt; &lt;activity android:name="com.example.mapgp.GmapwithgpsActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; </code></pre> <p></p> <p><strong>Logcat:</strong></p> <pre><code>01-04 22:36:54.120: D/AndroidRuntime(1510): Shutting down VM 01-04 22:36:54.120: W/dalvikvm(1510): threadid=1: thread exiting with uncaught exception (group=0x40015560) 01-04 22:36:54.251: E/AndroidRuntime(1510): FATAL EXCEPTION: main 01-04 22:36:54.251: E/AndroidRuntime(1510): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.mapgp/com.example.mapgp.GmapwithgpsActivity}: java.lang.ClassNotFoundException: com.example.mapgp.GmapwithgpsActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.example.mapgp-1.apk] 01-04 22:36:54.251: E/AndroidRuntime(1510): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569) 01-04 22:36:54.251: E/AndroidRuntime(1510): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 01-04 22:36:54.251: E/AndroidRuntime(1510): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 01-04 22:36:54.251: E/AndroidRuntime(1510): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 01-04 22:36:54.251: E/AndroidRuntime(1510): at android.os.Handler.dispatchMessage(Handler.java:99) 01-04 22:36:54.251: E/AndroidRuntime(1510): at android.os.Looper.loop(Looper.java:130) 01-04 22:36:54.251: E/AndroidRuntime(1510): at android.app.ActivityThread.main(ActivityThread.java:3683) 01-04 22:36:54.251: E/AndroidRuntime(1510): at java.lang.reflect.Method.invokeNative(Native Method) 01-04 22:36:54.251: E/AndroidRuntime(1510): at java.lang.reflect.Method.invoke(Method.java:507) 01-04 22:36:54.251: E/AndroidRuntime(1510): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 01-04 22:36:54.251: E/AndroidRuntime(1510): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 01-04 22:36:54.251: E/AndroidRuntime(1510): at dalvik.system.NativeStart.main(Native Method) 01-04 22:36:54.251: E/AndroidRuntime(1510): Caused by: java.lang.ClassNotFoundException: com.example.mapgp.GmapwithgpsActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.example.mapgp-1.apk] 01-04 22:36:54.251: E/AndroidRuntime(1510): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 01-04 22:36:54.251: E/AndroidRuntime(1510): at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 01-04 22:36:54.251: E/AndroidRuntime(1510): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 01-04 22:36:54.251: E/AndroidRuntime(1510): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 01-04 22:36:54.251: E/AndroidRuntime(1510): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561) 01-04 22:36:54.251: E/AndroidRuntime(1510): ... 11 more 01-04 22:37:24.730: I/Process(1510): Sending signal. PID: 1510 SIG: 9 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload