是否可以在處理程序中調用Toast?如果是這樣,怎麼樣?我當前的代碼正在生成NullPointer異常。在Handler消息中聲明Toast
這裏是我的代碼:
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)
示值誤差AT LINE:
Toast toast=Toast.makeText(getApplicationContext(),"THIS IS TOAST DIALOG",Toast.LENGTH_LONG);
您在哪裏初始化了prgBar。 – sankar
你在哪一行發生異常? –
顯示您的日誌信息 – koti