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
Handlerrefers to a class, butsendEmptyMessageis not a static method (should be called on an object, and not on a class).To be able to call the
sendEmptyMessagemethod you will eitherNeed to instantiate a
Handler, i.e., do something likeor
Add the
staticmodifier to thesendEmptyMessagemethod: