android.app.Application cannot be cast to android.app.Activity

后端 未结 5 1813
日久生厌
日久生厌 2020-11-28 09:33

I\'m trying to change a LinearLayout from another class, but when i run this code:

public class IRC extends PircBot {

ArrayList c         


        
5条回答
  •  我在风中等你
    2020-11-28 10:10

    You are passing the Application Context not the Activity Context with

    getApplicationContext();
    

    Wherever you are passing it pass this or ActivityName.this instead.

    Since you are trying to cast the Context you pass (Application not Activity as you thought) to an Activity with

    (Activity)
    

    you get this exception because you can't cast the Application to Activity since Application is not a sub-class of Activity.

提交回复
热议问题