gpt4 book ai didi

android - ProgressDialogue 抛出 NullPointerException

转载 作者:行者123 更新时间:2023-11-29 16:09:46 25 4
gpt4 key购买 nike

<分区>

我正在将 ProgressDialogue 与 AsyncTask 一起使用,但出现了 NullPointerException。

代码

public class MainActivity extends Activity {

//private MyProgressDialog dialog;
@Override
public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.activity_main);

new ProgressTask(MainActivity.this).execute();
}


/**
* this class performs all the work, shows dialog before the work and dismiss it after
*/
public class ProgressTask extends AsyncTask<String, Void, Boolean> {

private Activity context;

public ProgressTask(Activity mainActivity) {
this.activity = mainActivity;
dialog = new ProgressDialog(context);
}

/** progress dialog to show user that the backup is processing. */
private ProgressDialog dialog;
/** application context. */
private Activity activity;

protected void onPreExecute() {
this.dialog.setMessage("Progress start");
this.dialog.show();
}

@Override
protected void onPostExecute(final Boolean success) {
if (dialog.isShowing()) {
dialog.dismiss();
}
}

protected Boolean doInBackground(final String... args) {
try{

return true;
} catch (Exception e){
Log.e("tag", "error", e);
return false;
}
}
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com