扩展Android.app.application清单问题

发布于 2024-11-01 03:35:35 字数 6029 浏览 0 评论 0原文

当我尝试获取自定义应用程序类时,出现 classnotfoundException。 我的包结构:

be.test.helloworld.data.DataClass (extends Application ->not found)
be.test.helloworld.activities.MapGetLocationActivity (Activity -> works)

我认为问题出在我的清单中:

<!-- doesn't work -->
<application android:name=".data.DataClass" android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> 
<!-- this works -->
<activity android:label="@string/map" android:name=".activities.MapGetLocationActivity"></activity>

它曾经在应用程序标记中没有 android:name 的情况下工作。但现在当我尝试创建自定义应用程序对象时它不起作用。

是我的清单有问题吗?或者谁能​​告诉我问题所在?

我的自定义应用程序类与此处的最佳答案几乎相同(如何在 Android 中声明全局变量?

编辑:我的堆栈

04-15 10:25:33.434: WARN/dalvikvm(17609): threadid=1: thread exiting with uncaught exception (group=0x40028a00)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609): FATAL EXCEPTION: main
04-15 10:25:33.534: ERROR/AndroidRuntime(17609): java.lang.RuntimeException: Unable to instantiate application be.test.helloworld.data.DataClass: java.lang.ClassNotFoundException: be.test.helloworld.data.DataClass in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/be.test.helloworld-1.apk]
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:668)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4461)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread.access$3000(ActivityThread.java:135)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2176)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.os.Looper.loop(Looper.java:143)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread.main(ActivityThread.java:4914)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at java.lang.reflect.Method.invokeNative(Native Method)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at java.lang.reflect.Method.invoke(Method.java:521)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at dalvik.system.NativeStart.main(Native Method)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609): Caused by: java.lang.ClassNotFoundException: be.test.helloworld.data.DataClass in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/be.test.helloworld-1.apk]
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.Instrumentation.newApplication(Instrumentation.java:944)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:659)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     ... 11 more

跟踪编辑清单添加了:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="be.test.helloworld"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-feature android:name="android.hardware.camera.flash" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <application android:name=".data.DataClass"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
        <uses-library android:name="com.google.android.maps" />

        <activity android:label="@string/app_name"
            android:name=".activities.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:label="@string/map_get_location"
            android:name=".activities.MapGetLocationActivity">
        </activity>

        <receiver android:process=":remote"
            android:name=".timer.AlarmReceiver"></receiver>
    </application>
</manifest>

I get a classnotfoundexception when I try to get my custom application class.
My package structure:

be.test.helloworld.data.DataClass (extends Application ->not found)
be.test.helloworld.activities.MapGetLocationActivity (Activity -> works)

I think the problem is in my manifest:

<!-- doesn't work -->
<application android:name=".data.DataClass" android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> 
<!-- this works -->
<activity android:label="@string/map" android:name=".activities.MapGetLocationActivity"></activity>

It used to work without android:name in application tag. But now when I try to create a custom application object it doesnt't work.

Is it a problem with my manifest? Or can anyone tell me the problem?

My custom application class is almost identical to top answer here(How to declare global variables in Android?)

edit: my stacktrace

04-15 10:25:33.434: WARN/dalvikvm(17609): threadid=1: thread exiting with uncaught exception (group=0x40028a00)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609): FATAL EXCEPTION: main
04-15 10:25:33.534: ERROR/AndroidRuntime(17609): java.lang.RuntimeException: Unable to instantiate application be.test.helloworld.data.DataClass: java.lang.ClassNotFoundException: be.test.helloworld.data.DataClass in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/be.test.helloworld-1.apk]
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:668)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4461)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread.access$3000(ActivityThread.java:135)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2176)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.os.Looper.loop(Looper.java:143)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread.main(ActivityThread.java:4914)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at java.lang.reflect.Method.invokeNative(Native Method)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at java.lang.reflect.Method.invoke(Method.java:521)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at dalvik.system.NativeStart.main(Native Method)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609): Caused by: java.lang.ClassNotFoundException: be.test.helloworld.data.DataClass in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/be.test.helloworld-1.apk]
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.Instrumentation.newApplication(Instrumentation.java:944)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:659)
04-15 10:25:33.534: ERROR/AndroidRuntime(17609):     ... 11 more

edit manifest added:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="be.test.helloworld"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-feature android:name="android.hardware.camera.flash" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <application android:name=".data.DataClass"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
        <uses-library android:name="com.google.android.maps" />

        <activity android:label="@string/app_name"
            android:name=".activities.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:label="@string/map_get_location"
            android:name=".activities.MapGetLocationActivity">
        </activity>

        <receiver android:process=":remote"
            android:name=".timer.AlarmReceiver"></receiver>
    </application>
</manifest>

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

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

发布评论

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

评论(2

灯角 2024-11-08 03:35:35

尝试删除所有生成的文件并重建。我遇到过几次这样的错误,这通常会有所帮助。

try deleting all generated files and rebuilding. i had this sort of error a few times, and that usually helped.

独自唱情﹋歌 2024-11-08 03:35:35

今天升级到最新的 ADT/SDK 后遇到了此类问题。
我花了很长时间。
检查我是否使用了google-apis(用于地图),使用了库,清理了项目等。

删除了.project并添加了一个新的(创建新的android项目)最终解决了这个问题。

Had this sort of problem today after upgrading to latest ADT/SDK.
Took me quite a while.
Checked that i used google-apis (for maps), uses-library, cleaned the project etc.

Deleted the .project and added a fresh one (create new android project) finally solved it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文