是否可以从处理程序中调用 Toast?如果是这样,怎么做?我当前的代码正在生成 NullPointer 异常。
这是我的代码:
Handler messageHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
Toast toast=Toast.makeText(getApplicationContext(),"THIS IS TOAST DIALOG",Toast.LENGTH_LONG);
toast.show();
prgBar.setVisibility(prgBar.INVISIBLE);
}
};
我的日志报告:
09-13 18:18:51.493: E/AndroidRuntime(1727): FATAL EXCEPTION: main
09-13 18:18:51.493: E/AndroidRuntime(1727): java.lang.NullPointerException
09-13 18:18:51.493: E/AndroidRuntime(1727): at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:100)
09-13 18:18:51.493: E/AndroidRuntime(1727): at com.example.threadingexperiment.ThreadingExperiment$1.handleMessage(ThreadingExperiment.java:46)
在线显示错误:
Toast toast=Toast.makeText(getApplicationContext(),"THIS IS TOAST DIALOG",Toast.LENGTH_LONG);