我想创建一个MapView,但扩展MapActivity会抛出一个classNotFoundException:
/AndroidRuntime( 374): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
E/AndroidRuntime( 374): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 374): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 374): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 374): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 374): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 374): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 374): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 374): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 374): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 374): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 374): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 374): Caused by: java.lang.ClassNotFoundException: com.androidcourse.phonemapper.view.MapShowActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.androidcourse.phonemapper-2.apk]
E/AndroidRuntime( 374): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime( 374): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime( 374): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime( 374): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 374): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
我有一个Google Maps API密钥,我已将该项目设置为Google API,我使用的是Android Google API AVD(模拟器),我确实在AndroidManifest.xml中包含了该标记。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidcourse.phonemapper" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
.................
<activity android:name=".view.WelcomeActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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="api_key_is_here_just_wont_show_it_to_everybody"
/>
</RelativeLayout>
答案 0 :(得分:5)
我有完全相同的错误,我必须实现android:required =“true”语句,这已经留下了很多教程。
<uses-library
android:name="com.google.android.maps"
android:required="true" />
答案 1 :(得分:2)
另外,如果你忘了把
<uses-library android:name="com.google.android.maps" />
清单中标记内的标记,您将获得扩展MapActivity的活动的ClassNotFound异常:)
答案 2 :(得分:1)
尝试将包设置为“com.androidcourse.phonemapper.view”:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidcourse.phonemapper.view" android:versionCode="1"
android:versionName="1.0">
然后引用它:
<activity android:name=".WelcomeActivity"
答案 3 :(得分:1)
你应该在应用程序标签
中使用库标签<application>
<uses-library android:name="com.google.android.maps" android:required="true"/>
</application>