我使用Google SDK Eclipse创建了Google Map Marker示例项目。当涉及到执行时,bin文件似乎无法帮助我正确安装到设备上并使其工作。详细地说,Logcat显示以下消息:
类未找到异常错误日志
05-16 11:25:50.742: E/AndroidRuntime(25267): Process: com.example.testgpsmarker, PID: 25267
05-16 11:25:50.742: E/AndroidRuntime(25267): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.testgpsmarker/com.example.testgpsmarker.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.testgpsmarker.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.testgpsmarker-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testgpsmarker-2, /vendor/lib, /system/lib]]
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.os.Handler.dispatchMessage(Handler.java:102)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.os.Looper.loop(Looper.java:136)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-16 11:25:50.742: E/AndroidRuntime(25267): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 11:25:50.742: E/AndroidRuntime(25267): at java.lang.reflect.Method.invoke(Method.java:515)
05-16 11:25:50.742: E/AndroidRuntime(25267): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-16 11:25:50.742: E/AndroidRuntime(25267): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-16 11:25:50.742: E/AndroidRuntime(25267): at dalvik.system.NativeStart.main(Native Method)
05-16 11:25:50.742: E/AndroidRuntime(25267): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.testgpsmarker.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.testgpsmarker-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testgpsmarker-2, /vendor/lib, /system/lib]]
05-16 11:25:50.742: E/AndroidRuntime(25267): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
05-16 11:25:50.742: E/AndroidRuntime(25267): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
05-16 11:25:50.742: E/AndroidRuntime(25267): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
以下是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapview);
mc = mapView.getController();
int latitude = 22285520 ;
int longitude = 114157690;
showLocation(latitude,longitude);
}
private Handler h = new Handler(){
// Invoked by the method onTap()
// in the class CurrentLocationOverlay
@Override
public void handleMessage(Message msg) {
Bundle data = msg.getData();
// Getting the Latitude of the location
int latitude = data.getInt("latitude");
// Getting the Longitude of the location
int longitude = data.getInt("longitude");
// Show the location in the Google Map
showLocation(latitude,longitude);
}
};
protected void showLocation(int latitude, int longitude) {
// TODO Auto-generated method stub
mapView.setBuiltInZoomControls(true);
// Getting the MapController
MapController mapController = mapView.getController();
// Getting Overlays of the map
List<Overlay> overlays = mapView.getOverlays();
// Getting Drawable object corresponding to a resource image
Drawable drawable = getResources().getDrawable(R.drawable.marker);
// Creating an ItemizedOverlay
TouchedLocationOverlay locationOverlay = new TouchedLocationOverlay(drawable,h);
// Getting the MapController
MapController mc = mapView.getController();
// Creating an instance of GeoPoint, to display in Google Map
GeoPoint p = new GeoPoint(
latitude,
longitude
);
// Locating the point in the Google Map
mc.animateTo(p);
// Creating an OverlayItem to mark the point
OverlayItem overlayItem = new OverlayItem(p, "Item", "Item");
// Adding the OverlayItem in the LocationOverlay
locationOverlay.addOverlay(overlayItem);
// Clearing the overlays
overlays.clear();
// Adding locationOverlay to the overlay
overlays.add(locationOverlay);
// Redraws the map
mapView.invalidate();
}
\
布局
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:enabled="true"
android:apiKey="sdsdfsdfscdsfsdf" />
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testgpsmarker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.testgpsmarker.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我应该更正哪种配置?