0
我創建了包含ProgressDialog及其方法的Activity。android在構造函數中創建ProgressDialog
public class ProgressActivity extends AppCompatActivity implements Thread.UncaughtExceptionHandler {
public final ProgressDialog progressDialog;
public void dismissPD() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
public void setPDMessage(String msg) {
progressDialog.setMessage(msg);
}
public void showPD(String msg) {
ProgressDialog.show(this, "", msg);
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
ex.printStackTrace();
}
public ProgressActivity() {
progressDialog = new ProgressDialog(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
dismissPD();
}
}
現在,我從它延長我的新的活動,但我得到NullpointerException
內constructur上progressDialog = new ProgressDialog(this)
依我之見,我有一個錯誤的上下文構造運行時。我有沒有正確的方法來實現它?
progressDialog =新ProgressDialog(youractivity.this) – Sasi
progressDialog =新ProgressDialog(本);將此移至活動創建方法。 –
我想在父活動上取得進展Dialog private。那可能嗎? – Rainmaker