扩展Android.app.application清单问题

时间:2011-04-15 08:37:11

标签: android

当我尝试获取自定义应用程序类时,我得到了一个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工作。但是现在当我尝试创建一个自定义应用程序对象时,它不起作用。

我的清单有问题吗?或者有谁能告诉我这个问题?

我的自定义应用程序类与此处的最佳答案(How to declare global variables in 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>

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

删除了.project并添加了一个新的(创建新的android项目)终于解决了它。