我想在我的应用程序上显示谷歌地图,我正在使用谷歌地图v2,我做了所有步骤,但我仍然有这些错误和应用程序在启动时崩溃... 这是logcat:
07-21 11:24:02.808: E/AndroidRuntime(592): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.testmap/com.example.testmap.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.testmap.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.testmap-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testmap-2, /system/lib]]
07-21 11:38:26.698: E/AndroidRuntime(673): FATAL EXCEPTION: main
07-21 11:38:26.698: E/AndroidRuntime(673): Process: com.example.testmap, PID: 673
07-21 11:38:26.698: E/AndroidRuntime(673): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.testmap/com.example.testmap.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.testmap.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.testmap-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testmap-1, /system/lib]]
07-21 11:38:26.698: E/AndroidRuntime(673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2134)
07-21 11:38:26.698: E/AndroidRuntime(673): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2270)
07-21 11:38:26.698: E/AndroidRuntime(673): at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-21 11:38:26.698: E/AndroidRuntime(673): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-21 11:38:26.698: E/AndroidRuntime(673): at android.os.Handler.dispatchMessage(Handler.java:102)
07-21 11:38:26.698: E/AndroidRuntime(673): at android.os.Looper.loop(Looper.java:136)
07-21 11:38:26.698: E/AndroidRuntime(673): at android.app.ActivityThread.main(ActivityThread.java:5042)
07-21 11:38:26.698: E/AndroidRuntime(673): at java.lang.reflect.Method.invokeNative(Native Method)
07-21 11:38:26.698: E/AndroidRuntime(673): at java.lang.reflect.Method.invoke(Method.java:515)
07-21 11:38:26.698: E/AndroidRuntime(673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:776)
07-21 11:38:26.698: E/AndroidRuntime(673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-21 11:38:26.698: E/AndroidRuntime(673): at dalvik.system.NativeStart.main(Native Method)
07-21 11:38:26.698: E/AndroidRuntime(673): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.testmap.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.testmap-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testmap-1, /system/lib]]
07-21 11:38:26.698: E/AndroidRuntime(673): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-21 11:38:26.698: E/AndroidRuntime(673): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
07-21 11:38:26.698: E/AndroidRuntime(673): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
07-21 11:38:26.698: E/AndroidRuntime(673): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
07-21 11:38:26.698: E/AndroidRuntime(673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2125)
07-21 11:38:26.698: E/AndroidRuntime(673): ... 11 more
Mainctivity.java
package com.example.testmap;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activitymain.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.testmap.MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment "/>
</RelativeLayout>
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testmap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<permission android:name="com.example.testmap.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.testmap.permission.MAPS_RECEIVE"/>
<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"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key "/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>