android google maps issue
In the program below i am trying to use google map from the following example http://www.vogella.de/articles/AndroidLocationAPI/article.html , i have followed exactly all the steps in the example but some how i am not able t execute it the APP closes down .
Below is my code.Let me know what am i doing wrong here
package ShowMap.com;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.widget.RelativeLayout;
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 ShowmapActivity extends MapActivity {
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mainlayout);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setStreetView(true);
mapController = mapView.getController();
mapController.setZoom(14); // Zoon 1 is world view
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new GeoUpdateHandler());
}
protected boolean isRouteDisplayed() {
return false;
}
public class GeoUpdateHandler implements LocationListener {
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
GeoPoint point = new GeoPoint(lat, lng);
mapController.animateTo(point); // mapController.setCenter(point);
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
}
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0YjDTTmg77Hdf9GVv26GW1123452v4ssZererHikVw"
/>
Android manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ShowMap.com"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-library android:required="true" android:name="com.google.android.maps"></uses-library>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ShowmapActivity"
android:label="@string/ap开发者_StackOverflowp_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<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" />
</manifest>
EDIT:This is the logcat trace
07-18 15:20:46.065: DEBUG/AndroidRuntime(469): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
07-18 15:20:46.096: DEBUG/AndroidRuntime(469): CheckJNI is ON
07-18 15:20:50.572: DEBUG/AndroidRuntime(472): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
07-18 15:20:50.572: DEBUG/AndroidRuntime(472): CheckJNI is ON
07-18 15:20:54.486: DEBUG/AndroidRuntime(469): --- registering native functions ---
07-18 15:20:54.511: DEBUG/AndroidRuntime(472): --- registering native functions ---
07-18 15:21:09.085: DEBUG/dalvikvm(472): DexOpt: sleeping on flock(/data/dalvik-cache/system@framework@pm.jar@classes.dex)
07-18 15:21:10.252: DEBUG/AndroidRuntime(469): Shutting down VM
07-18 15:21:10.266: INFO/AndroidRuntime(469): NOTE: attach of thread 'Binder Thread #3' failed
07-18 15:21:10.305: DEBUG/dalvikvm(469): Debugger has detached; object registry had 1 entries
07-18 15:21:13.498: DEBUG/dalvikvm(279): GC_EXPLICIT freed 114 objects / 5848 bytes in 1347ms
07-18 15:21:13.916: DEBUG/PackageParser(66): Scanning package: /data/app/vmdl20199.tmp
07-18 15:21:14.051: WARN/PackageParser(66): Unknown element under <manifest>: uses-library at /data/app/vmdl20199.tmp Binary XML file line #7
07-18 15:21:15.378: INFO/PackageManager(66): Removing non-system package:ShowMap.com
07-18 15:21:15.378: INFO/ActivityManager(66): Force stopping package ShowMap.com uid=10040
07-18 15:21:15.835: DEBUG/PackageManager(66): Scanning package ShowMap.com
07-18 15:21:15.845: INFO/PackageManager(66): Package ShowMap.com codePath changed from /data/app/ShowMap.com-1.apk to /data/app/ShowMap.com-2.apk; Retaining data and using new
07-18 15:21:15.867: INFO/PackageManager(66): /data/app/ShowMap.com-2.apk changed; unpacking
07-18 15:21:15.935: DEBUG/installd(35): DexInv: --- BEGIN '/data/app/ShowMap.com-2.apk' ---
07-18 15:21:16.495: DEBUG/dalvikvm(485): DexOpt: load 75ms, verify 122ms, opt 10ms
07-18 15:21:16.515: DEBUG/installd(35): DexInv: --- END '/data/app/ShowMap.com-2.apk' (success) ---
07-18 15:21:16.555: INFO/ActivityManager(66): Force stopping package ShowMap.com uid=10040
07-18 15:21:16.555: WARN/PackageManager(66): Code path for pkg : ShowMap.com changing from /data/app/ShowMap.com-1.apk to /data/app/ShowMap.com-2.apk
07-18 15:21:16.575: WARN/PackageManager(66): Resource path for pkg : ShowMap.com changing from /data/app/ShowMap.com-1.apk to /data/app/ShowMap.com-2.apk
07-18 15:21:16.595: DEBUG/PackageManager(66): Activities: ShowMap.com.ShowmapActivity
07-18 15:21:16.875: INFO/installd(35): move /data/dalvik-cache/data@app@ShowMap.com-2.apk@classes.dex -> /data/dalvik-cache/data@app@ShowMap.com-2.apk@classes.dex
07-18 15:21:16.875: DEBUG/PackageManager(66): New package installed in /data/app/ShowMap.com-2.apk
07-18 15:21:17.187: INFO/ActivityManager(66): Force stopping package ShowMap.com uid=10040
07-18 15:21:17.610: DEBUG/dalvikvm(66): GC_EXPLICIT freed 13050 objects / 728192 bytes in 342ms
07-18 15:21:20.477: DEBUG/dalvikvm(123): GC_EXPLICIT freed 1150 objects / 59528 bytes in 2120ms
07-18 15:21:27.735: WARN/RecognitionManagerService(66): no available voice recognition services found
07-18 15:21:30.515: DEBUG/dalvikvm(66): GC_EXPLICIT freed 3973 objects / 218952 bytes in 589ms
07-18 15:21:31.946: INFO/installd(35): unlink /data/dalvik-cache/data@app@ShowMap.com-1.apk@classes.dex
07-18 15:21:32.034: DEBUG/AndroidRuntime(472): Shutting down VM
07-18 15:21:32.045: DEBUG/dalvikvm(472): Debugger has detached; object registry had 1 entries
07-18 15:21:32.085: INFO/AndroidRuntime(472): NOTE: attach of thread 'Binder Thread #3' failed
07-18 15:21:33.235: DEBUG/AndroidRuntime(491): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
07-18 15:21:33.235: DEBUG/AndroidRuntime(491): CheckJNI is ON
07-18 15:21:33.735: DEBUG/AndroidRuntime(491): --- registering native functions ---
07-18 15:21:35.950: INFO/ActivityManager(66): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=ShowMap.com/.ShowmapActivity }
07-18 15:21:37.315: DEBUG/AndroidRuntime(491): Shutting down VM
07-18 15:21:37.324: INFO/AndroidRuntime(491): NOTE: attach of thread 'Binder Thread #3' failed
07-18 15:21:37.366: DEBUG/dalvikvm(491): Debugger has detached; object registry had 1 entries
07-18 15:21:39.699: INFO/ActivityManager(66): Start proc ShowMap.com for activity ShowMap.com/.ShowmapActivity: pid=498 uid=10040 gids={3003}
07-18 15:21:43.026: WARN/dalvikvm(498): Unable to resolve superclass of LShowMap/com/ShowmapActivity; (20)
07-18 15:21:43.026: WARN/dalvikvm(498): Link of class 'LShowMap/com/ShowmapActivity;' failed
07-18 15:21:43.096: DEBUG/AndroidRuntime(498): Shutting down VM
07-18 15:21:43.096: WARN/dalvikvm(498): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): FATAL EXCEPTION: main
07-18 15:21:43.295: ERROR/AndroidRuntime(498): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ShowMap.com/ShowMap.com.ShowmapActivity}: java.lang.ClassNotFoundException: ShowMap.com.ShowmapActivity in loader dalvik.system.PathClassLoader[/data/app/ShowMap.com-2.apk]
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at android.os.Looper.loop(Looper.java:123)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at java.lang.reflect.Method.invoke(Method.java:521)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at dalvik.system.NativeStart.main(Native Method)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): Caused by: java.lang.ClassNotFoundException: ShowMap.com.ShowmapActivity in loader dalvik.system.PathClassLoader[/data/app/ShowMap.com-2.apk]
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
07-18 15:21:43.295: ERROR/AndroidRuntime(498): ... 11 more
07-18 15:21:43.364: WARN/ActivityManager(66): Force finishing activity ShowMap.com/.ShowmapActivity
07-18 15:21:43.915: WARN/ActivityManager(66): Activity pause timeout for HistoryRecord{44f9e8b8 ShowMap.com/.ShowmapActivity}
Make sure not only the AVD but also the target of your code must be set on Google API and not Android API. Check this in your default.properties file. If it's currently set to Android API, you can change it like this way: Select your project folder > properties > android > In the project build target select the Google API for your API level. Save All and it's done!
Have nice development!
精彩评论