Extending Android.app.application manifest problem
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:开发者_C百科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>
try deleting all generated files and rebuilding. i had this sort of error a few times, and that usually helped.
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.
精彩评论