我有一个错误无法作出从类型处理器的静态引用非静态方法sendEmptyMessage(INT)
如何解决?因为我觉得这是一个问题,这个类,我这样做是不是一个活动?
新的Thread(){
公共无效的run(){
尝试 {
名单<赛欧>帆= searchSails();
selectSailIntent.putParcelableArrayListExtra(
Constant.SAILS,新的ArrayList<赛欧>(帆));
。的getContext()startActivity(selectSailIntent);
Handler.sendEmptyMessage(0);
}赶上(例外五){
alertDialog.setMessage(e.getMessage());
Handler.sendEmptyMessage(1);
}
}
}。开始();
}
};
解决方案
不能让从类型处理器的静态引用非静态方法sendEmptyMessage(INT)的
这是由于这一事实,即处理程序
是指一类,但 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();
}
};
解决方案
"Cannot make a static reference to the non-static method sendEmptyMessage(int) from the type Handler"
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).
How to fix it?
To be able to call the sendEmptyMessage
method you will either
Need to instantiate a Handler
, i.e., do something like
Handler h = new Handler();
h.sendEmptyMessage(0);
or
Add the static
modifier to the sendEmptyMessage
method:
public static void sendEmptyMessage(int i) { ...
^^^^^^