android.app.Application无法转换为android.app.Activity。
android.app.Application无法转换为android.app.Activity。
我试图从另一个类改变一个LinearLayout,但是当我运行这段代码时:
public class IRC extends PircBot {
ArrayList
ArrayList
ArrayList
LinearLayout channelLayout;
Context context;
public IRC(Context ctx) {
this.setName("xxxx");
channels = new ArrayList
userCount = new ArrayList
topics = new ArrayList
context = ctx;
channelLayout = (LinearLayout) ((Activity) context).findViewById(R.id.channels);
}
}
我收到一个ClassCastException的错误。
context是扩展了Activity的主活动,通过getApplicationContext()传递;
LOGCAT
05-08 17:53:55.102 3736-3799/g.d.allinonechat E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-5357
java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity
at g.d.xxx.IRC.
at g.d.xxx.MainActivity$1.run(MainActivity.java:49)
at java.lang.Thread.run(Thread.java:856)