当我点击我的注册按钮应用程序崩溃和logcat指向此
private void registerUser(final String name, final String email,
final String password) {
String tag_string_req = "req_register";
//crash occurs here
pDialog.setMessage("please wait");
showDialog();
StringRequest strReq = new StringRequest(Method.POST,
AppConfig.URL_REGISTER, new Response.Listener<String>() {
我可以用另一种方式显示进度对话框吗?
这就是logcat显示的内容
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ProgressDialog.setMessage(java.lang.CharSequence)' on a null object reference
at com.chat.RegisterFragment.registerUser(RegisterFragment.java:132)
at com.chat.RegisterFragment.access$300(RegisterFragment.java:49)
at com.chat.RegisterFragment$2.onClick(RegisterFragment.java:106)
at android.view.View.performClick(View.java:5698)
at android.widget.TextView.performClick(TextView.java:10891)
at android.view.View$PerformClick.run(View.java:22533)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
答案 0 :(得分:1)
您的对话框为空,因此您需要在使用它之前对其进行初始化:
private void registerUser(final String name, final String email,
final String password) {
String tag_string_req = "req_register";
pDialog = new AlertDialog.Builder(getActivity());
pDialog.setMessage("please wait");
pDialog.show();
StringRequest strReq = new StringRequest(Method.POST,
AppConfig.URL_REGISTER, new Response.Listener<String>() {