Abhishek
Abhishek

Reputation: 1779

Error When creating an Application class in Android

I followed the advice given on the internet regarding working with Application classes in android. I also added a field "android:name=.Session" to my Application object in the manifest.

The application is called "Session".

What do you think is the error? This is happening even before the my App starts.

This is the error stack:

**java.lang.RuntimeException: Unable to instantiate application com.appfire.Session: java.lang.InstantiationException: com.appfire.Session**
 at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:523)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3996)
at android.app.ActivityThread.access$2900(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1901)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
 **Caused by: java.lang.InstantiationException: com.appfire.Session**
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1479)
at android.app.Instrumentation.newApplication(Instrumentation.java:957)
at android.app.Instrumentation.newApplication(Instrumentation.java:942)
at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:518)

Upvotes: 0

Views: 868

Answers (3)

Jaap D
Jaap D

Reputation: 499

My solution was to delete the whole project from Eclipse and load it again from SVN. Now it works

Upvotes: 0

marchica
marchica

Reputation: 2416

Make sure your Session class is public, is not static, and does not have a default constructor.

public class Session extends Application {}

Upvotes: 1

mportuesisf
mportuesisf

Reputation: 5617

In the Manifest application tag, make sure you include the fully-qualified class name of your custom Application object:

<application
    android:name="com.mycompany.myapp.Session"
    ....  />

The Android docs do say the class name must be fully qualified:

http://developer.android.com/guide/topics/manifest/application-element.html#nm

(This is not the case for Activity class names that are included in the activity tag of the Manifest. Those can be relative, preceded with a '.').

Upvotes: 0

Related Questions