更新时间:2022-11-16 22:29:41
您传递的是 Application Context
而不是 Activity Context
与
You are passing the Application Context
not the Activity Context
with
getApplicationContext();
无论你在哪里传递它,都通过 this
或 ActivityName.this
代替.
Wherever you are passing it pass this
or ActivityName.this
instead.
由于您试图将 Context
传递给 Activity
与
Since you are trying to cast the Context
you pass (Application not Activity as you thought) to an Activity
with
(Activity)
你得到这个异常是因为你不能将 Application 转换为 Activity
因为 Application 不是 Activity
的子类.
you get this exception because you can't cast the Application to Activity
since Application is not a sub-class of Activity
.