问题描述
我有一个错误无法作出从类型处理器的静态引用非静态方法sendEmptyMessage(INT)
如何解决?因为我觉得这是一个问题,这个类,我这样做是不是一个活动?
新的Thread(){
公共无效的run(){
尝试 {
名单<赛欧>帆= searchSails();
selectSailIntent.putParcelableArrayListExtra(
Constant.SAILS,新的ArrayList<赛欧>(帆));
。的getContext()startActivity(selectSailIntent);
Handler.sendEmptyMessage(0);
}赶上(例外五){
alertDialog.setMessage(e.getMessage());
Handler.sendEmptyMessage(1);
}
}
}。开始();
}
};
这是由于这一事实,即处理程序
是指一类,但 sendEmptyMessage
不是一个静态方法(应称为一个对象,而不是在一个类)上
要能够调用的 sendEmptyMessage
方法,你要么
-
需要的实例化的一个
处理程序
,即做这样的事情处理程序H =新的处理程序(); h.sendEmptyMessage(0);
或
-
添加
静态
修改为sendEmptyMessage
方法:公共静态无效sendEmptyMessage(int i)以{... ^^^^^^
I have an error "Cannot make a static reference to the non-static method sendEmptyMessage(int) from the type Handler"
How to fix it? As I think this is a problem that this class where I do this is not an activity?
new Thread() {
public void run() {
try {
List<Sail> sails = searchSails();
selectSailIntent.putParcelableArrayListExtra(
Constant.SAILS, new ArrayList<Sail>(sails));
getContext().startActivity(selectSailIntent);
Handler.sendEmptyMessage(0);
} catch (Exception e) {
alertDialog.setMessage(e.getMessage());
Handler.sendEmptyMessage(1);
}
}
}.start();
}
};
This is due to the fact that Handler
refers to a class, but sendEmptyMessage
is not a static method (should be called on an object, and not on a class).
To be able to call the sendEmptyMessage
method you will either
Need to instantiate a
Handler
, i.e., do something likeHandler h = new Handler(); h.sendEmptyMessage(0);
or
Add the
static
modifier to thesendEmptyMessage
method:public static void sendEmptyMessage(int i) { ... ^^^^^^
这篇关于不能让从类型处理器的静态引用非静态方法sendEmptyMessage(INT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!