Android::扩展MapActivity =>类未找到异常

发布于 2024-10-09 12:41:50 字数 3843 浏览 13 评论 0原文

我想做一个 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>

I'd like to make a MapView, but extending the MapActivity throws a 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)

I have a Google Maps API key, I had set the project to be for Google APIs, I am using an Android Google API AVD(emulator) and I did include the tag in my 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

山色无中 2024-10-16 12:41:50

我遇到了完全相同的错误,我必须实现 android:required="true" 语句,该语句已经在很多教程中留下了。

<uses-library
            android:name="com.google.android.maps"
            android:required="true" />

I had the exact same error for me I had to implement the android:required="true" statement, which has been left of a lot of tutorials.

<uses-library
            android:name="com.google.android.maps"
            android:required="true" />
°如果伤别离去 2024-10-16 12:41:50

另外,如果您忘记将

<uses-library android:name="com.google.android.maps" />

标签放入清单中的标签内,您的活动将得到一个 ClassNotFound 异常,该异常扩展了 MapActivity :)

Also, if you forget to put the

<uses-library android:name="com.google.android.maps" />

tag inside your tag in your manifest you will get a ClassNotFound Exception for your activity that extends MapActivity :)

比忠 2024-10-16 12:41:50

尝试将包设置为“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"

Try setting package to "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">

and then referencing it:

<activity android:name=".WelcomeActivity"
日暮斜阳 2024-10-16 12:41:50

你应该在应用程序标签内使用-library标签

<application>
<uses-library android:name="com.google.android.maps" android:required="true"/>
</application>

you should uses-library tag inside application tag

<application>
<uses-library android:name="com.google.android.maps" android:required="true"/>
</application>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文