Reputation: 1838
This happens every time I upgrade, usually for different reasons: I just upgraded to Android Studio 4, I'm targeting android 5/Api21 upwards. This time my activity crashes on start up with claiming that my main activity 'is not accessible from class android.app.Instrumentation'
I'm not sure what 'android.app.Instrumentation' is or whether there's some requirement in my code, a dependency or android studio that's requiring it. My main class is public so it should be able to see it.
My class declaration looks like this:
public class AnthracitePlayer extends AppCompatActivity
and AppCompatActivity, which I believe is something I used to remove the title bar is declared like this:
public class AppCompatActivity extends FragmentActivity implements AppCompatCallback,
TaskStackBuilder.SupportParentable, ActionBarDrawerToggle.DelegateProvider {
and my create method starts like this:
Override
public void onCreate(Bundle savedInstanceState)
{
Log.d(TAG,"Entered onCreate");
super.onCreate(savedInstanceState);
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
String displayName = display.getName();
I'm not sure if any of those is upsetting this instrumentation thing. The error follows:
07-12 14:32:26.251 20528-20528/totga.anthraciteplayerapi21 D/ResourcesManager: creating new AssetManager and set to /data/app/totga.anthraciteplayerapi21-2/base.apk 07-12 14:32:26.341 20528-20528/totga.anthraciteplayerapi21 D/AndroidRuntime: Shutting down VM 07-12 14:32:26.341 20528-20528/totga.anthraciteplayerapi21 E/AndroidRuntime: FATAL EXCEPTION: main Process: totga.anthraciteplayerapi21, PID: 20528 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{totga.anthraciteplayerapi21/totga.anthraciteplayerapi21.AnthracitePlayer}: java.lang.IllegalAccessException: totga.anthraciteplayerapi21.AnthracitePlayer() is not accessible from class android.app.Instrumentation at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2515) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5832) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: java.lang.IllegalAccessException: totga.anthraciteplayerapi21.AnthracitePlayer() is not accessible from class android.app.Instrumentation at java.lang.Class.newInstance(Class.java:1647) at android.app.Instrumentation.newActivity(Instrumentation.java:1079) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2505) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5832) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Upvotes: 0
Views: 66
Reputation: 1838
I managed to get this to run (although I have new problems now) by changing onCreate from 'public' to 'protected'. What I think happened is that either the permissions in the parent class inside the android library changed or the rules governing access levels became more strict - public should have worked either way.
Upvotes: 0