- Forum posts: 11
Apr 15, 2017, 11:48:13 AM via Website
Apr 15, 2017 11:48:13 AM via Website
i have faced pblm when i clicked on login button on login activity.this is my debug logact:
04-15 15:07:45.924 2533-2533/volleyjson.androidhive.info.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: volleyjson.androidhive.info.myapplication, PID: 2533
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.app.ProgressDialog.isShowing()' on a null object reference
at volleyjson.androidhive.info.myapplication.login.showProgressDialog(login.java:55)
at volleyjson.androidhive.info.myapplication.login.makeJsonObjReq(login.java:64)
this is my login activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_dialogue);
t1 = (TextView) findViewById(R.id.textView1);
t2 = (TextView) findViewById(R.id.textView2);
t3 = (TextView) findViewById(R.id.textView3);
ed1 = (EditText) findViewById(R.id.RegEmail);
b1 = (Button) findViewById(R.id.btnLogin);
b1.setOnClickListener(this);
ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
}
private void showProgressDialog() {
if (!pDialog.isShowing())
pDialog.show();
}
private void hideProgressDialog() {
if (pDialog.isShowing())
pDialog.hide();
}
private void makeJsonObjReq() {
showProgressDialog();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
LOGIN_URL , null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
openProfile();
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hideProgressDialog();
}
}) {
/**
* Passing some request headers
* */
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
return headers;
}
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put(KEY_EMAIL, email);
return params;
}
};
// Adding request to request queue
String tag_json_obj = "jsonObjReq ";
AppController.getInstance().addToRequestQueue(jsonObjReq,
tag_json_obj);
// Cancelling request
// ApplicationController.getInstance().getRequestQueue().cancelAll(tag_json_obj);
}
private void openProfile(){
Intent intent = new Intent(login.this, MainActivity.class);
intent.putExtra(KEY_EMAIL,email);
startActivity(intent);
}
@Override
public void onClick(View v) {
makeJsonObjReq();
}
}
at volleyjson.androidhive.info.myapplication.login.onClick(login.java:120)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
— modified on Apr 15, 2017, 11:49:35 AM
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.