Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: java.lang.IllegalAccessException when attempting to use a custom "Application" class

Tags:

android

I'm trying to create define a custom Application class as follows:

  1. create an empty subclass of Application called MyApp
  2. in the manifest, specify android::name for my application: <application android:name=".MyApp" ...

However, when I attempt to run my app, I get: java.lang.RuntimeException: Unable to instantiate application com.test.MyApp java.lang.IllegalAccessException: access to class not allowed

like image 562
zer0stimulus Avatar asked Jul 19 '10 02:07

zer0stimulus


2 Answers

Make sure your custom class is public, has a public zero-argument constructor, and that the constructor chains to the superclass' constructor.

like image 148
CommonsWare Avatar answered Oct 20 '22 13:10

CommonsWare


I agree with CommonsWare. If you extend android.app.Application to define custom application for your project, make sure that you have marked your class as public and public no-agrs constructor as well.

However, on android.app.Application API its mentioned that, There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way.

Hope this will help.

Cheers.

like image 35
Shekh Akther Avatar answered Oct 20 '22 14:10

Shekh Akther