heroku H12 error with Volley - android

I recently wrote a android app with volley to do the http request,
At first,I used local host to work as a server,it worked perfectly.
However, as I moved my node.js code to heroku server, my app will often get timeout error.
The log from heroku like
2016-04-23T00:59:01.653405+00:00 heroku[router]: at=info method=POST path="/ispassword" host=lit-island-38801.herokuapp.com request_id=1273b9e7-6632-4117-b68f-5d7d8eb83b52 fwd="152.3.43.156" dyno=web.1 connect=1ms service=27ms status=200 bytes=224
2016-04-23T00:59:33.426223+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/ispassword" host=lit-island-38801.herokuapp.com request_id=e861aa6f-c40b-440c-af1c-3a24eded9c2c fwd="152.3.43.156" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0
And my android app request code is like this
RequestQueue queue = Volley.newRequestQueue(Login.this);
StringRequest strRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>()
{
#Override
public void onResponse(String response)
{
Log.d(TAG,response);
if(response.equals("no")){
onLoginFailed();
Toast.makeText(getBaseContext(), "Login failed", Toast.LENGTH_LONG).show(); //show the toast for a long time
Intent intent = new Intent(Login.this, Login.class);
startActivity(intent);
finish();
}
//Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
String del =":";
String []res = response.split(del);
fetched_pw = res[1].replaceAll("\\}","").replaceAll("\"","").replaceAll("\\]","");
Log.i(TAG,fetched_pw);
Log.i(TAG,password);
Log.i(TAG,"version1");
if(password.equals(fetched_pw)){
progressDialog.show();
onLoginSuccess();
progressDialog.dismiss();
}
else{
onLoginFailed();
progressDialog.dismiss();
}
}
},
new Response.ErrorListener()
{
#Override
public void onErrorResponse(VolleyError error)
{
Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
}
})
{
#Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
params.put("email", email);
return params;
}
};
queue.add(strRequest);
}
And my node.js code to handle this is like
app.post('/ispassword', function (req, res) {
var pg = require('pg');
var ans;
pg.defaults.ssl = true;
pg.connect("postgres://abcdefghij:ev0Y_GVqmX5zd22oM3KQ8smXS5#ec2-11-11-11-111-1-1.compute-1.amazonaws.com:5432/d4drnop61h6hv7", function(err, client) {
if (err) throw err;
console.log('Get to Function ispassword');
var email = req.param('email');
client.query("select password from USER_TABLE where email = $1;",[email],function (error,results) {
if(results.rowCount>0){
var que = client.query("select password from USER_TABLE where email = $1;",[email]);
//var que = client.query("select password from USER_TABLE");
que.on("row", function (row, result) {
//console.log(row);
result.addRow(row);
});
que.on("end", function (result) {
res.send(result.rows);
});
console.log("send");
}
else{
res.send('no');
}
});
});
});
Can someone save my day please??

Related

Error on progressDialog and Toast with custom recyclerview adapter file

I need help for showing toast and progress dialog inside volley request, and I use a custom adapter file when click on the card will send data with volley, please give better flow or fixing this code.
this is my onBindViewHolder inside adapter file
#Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
final DataPicking task = taskList.get(position);
holder.numberid.setText(task.getNomorid());
holder.nama.setText(task.getNamakonsumen());
holder.rate.setText(task.getRate());
holder.tanggal.setText(task.getTanggal());
holder.salesman.setText(task.getSalesman());
holder.cardList.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View view) {
new AlertDialog.Builder(view.getContext())
.setTitle("Proses Picking")
.setMessage("Apakah kamu yakin ingin memproses picking data ini?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String nomorid = taskList.get(position).getNomorid();
PickingActivity picking = new PickingActivity();
picking.kirimData(nomorid);
}})
.setNegativeButton(android.R.string.no, null).show();
}
});
}
and this is kirimData function for send data with volley
public void kirimData(final String nomorid){
// Log.e("ini kirimdata ",nomorid);
// Tag used to cancel the request
String tag_string_req = "req_login";
pDialog.setMessage("Loading ...");
showDialog();
StringRequest strReq = new StringRequest(Request.Method.POST,
Constants.URL_SET_PICKING, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d(TAG, "Picking Response: " + response.toString());
//hideDialog();
try {
JSONObject jObj = new JSONObject(response);
Log.e(TAG, "obj: " + jObj.toString());
String error = jObj.getString("status");
Log.e(TAG, "obj: " + error);
// Check for error node in json
if (error.equals("1")) {
// user successfully logged in
// Create login session
mAdapter.notifyDataSetChanged();
} else {
// Error in login. Get the error message
String errorMsg = jObj.getString("message");
Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getBaseContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
/*Intent intent = new Intent(LoginActivity.this,
MainActivity.class);
startActivity(intent);
finish();*/
Log.e(TAG, "Proses Picking Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
"Proses Picking Failed", Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
#Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<String, String>();
params.put("nomorid", nomorid);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
and this is the error log
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ProgressDialog.setMessage(java.lang.CharSequence)' on a null object reference
at com.sip.gotrack.PickingActivity.kirimData(PickingActivity.java:167)
at com.sip.gotrack.PickingAdapter$1$1.onClick(PickingAdapter.java:69)
please help me for this error
Where is your pDialog being initialized?
Inside kirimData, initialize pDialog like this in the beginning.
pDialog = new ProgressDialog(context);
It seems pDialog is not initialized before this method is called.

Android app communicate with Node.Js server and MongoDB

I am building a login in my android app. I am trying to make to make my app communicate with a Node.JS server using volley to make network request. The node.js server is already setup and is running. I made sure that my PC and my android phone are on the same network (I really don't know if this is necessary). Also Mongo DB is setup and running. But I get an error response when I try to login. This is my code:
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String getLoginEmail = loginEmail.getText().toString();
String getLoginPassword = loginPassword.getText().toString();
if (!TextUtils.isEmpty(getLoginEmail) && !TextUtils.isEmpty(getLoginPassword)) {
loginUser(getLoginEmail, getLoginPassword);
} else if...
}
});...
private void loginUser(final String gottenLoginEmail, final String gottenLoginPassword) {
final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this);
progressDialog.setMessage(getString(R.string.logging_in));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
StringRequest stringRequest = new StringRequest(Request.Method.POST, Constants.URL_LOGIN, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.i("onResponse", response);
progressDialog.dismiss();
try {
JSONObject jsonObject = new JSONObject(response);
Log.i("Response", response); //logged response
//check if response at first position (index 0) equals success
if (jsonObject.names().get(0).equals("success")) {
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
} else {
...
}
} catch (JSONException e) {
Log.i("Exception", e.getMessage()); //logged exception
Snackbar.make(findViewById(R.id.login_activity), e.getMessage(), Snackbar.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.i("Error", "ERRROR: " + error.getMessage()); //logged error. Refer to debugger image below
progressDialog.dismiss();
Snackbar.make(findViewById(R.id.login_activity), error.getMessage(), Snackbar.LENGTH_SHORT).show();
}
}) {
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("email", gottenLoginEmail);
params.put("password", gottenLoginPassword);
return params;
}
};
RequestHandler.getInstance(LoginActivity.this).addToRequestQueue(stringRequest);
}
In my Constants Java Class I have the following:
public class Constants {
public static final String ROOT_URL = "http://192.168.43.1:5000/api/user/auth/";
public static final String URL_LOGIN = ROOT_URL + "signin";
public static final String URL_REGISTER = ROOT_URL + "signup";
//192.168.43.1 is the DHCP server of the network my pc and android phone is connected to
//5000 is the node.js application port i.e. localhost:5000
}
Please I need help. I have been battling with this for 3 days now...
When I run the app I get this in the debugger console
N.B. "localhost:5000/api/user/auth/signin" is the API endpoint login route.
I think your trouble is Firewall try to disable it
if your OC is windows follow this guide https://www.youtube.com/watch?v=dlBgoVMXIWo

Android Studio MySql Login

I recently started using MySql to connect to my android app and I'm stuck at the login. I don't what's wrong but when I try to login, nothing happens.
Here's my PHP Code
<?php
$user_name = filter_input(INPUT_POST, "username");
$user_pass = filter_input(INPUT_POST, "password");
$conn = new mysqli("localhost", "root", "Hadassa1998", "vodadb");
$query = mysqli_query ($conn, "select * from vodainfos where username =
'".$user_name."' and password = '".$user_pass."'");
if($rez= mysqli_fetch_array($conn)){
echo "Login RĂ©ussi";
}
else{
echo "Echec Login";
}
?>
And Over here is my Java Code
usrnm= findViewById(R.id.user_login);
pass= findViewById(R.id.motdepasse);
button= findViewById(R.id.btn_login);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
loginclass();
}
});
}
Here's where the login Happens. I don't know what I am doing wrong
I think the issue is with the URL but I am not sure. It won't open the next activity and it won't throw the error message either
The IP is a dummy
public void loginclass() {
StringRequest stringRequest= new StringRequest(Request.Method.POST,
"http://192.168.73.147/login.php", new Response.Listener<String>() {
#Override
public void onResponse(String response) {
if(response.contains ("1")) {
startActivity(new Intent(getApplicationContext(),
Menu.class));
}
else {
Toast.makeText(Connexion.this, "Username ou Mot de passe
incorrect", Toast.LENGTH_SHORT).show();
}
}
}, new Response.ErrorListener(){
#Override
public void onErrorResponse(VolleyError error) {
}
}){
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params= new HashMap<>();
params.put("username",usrnm.getText().toString());
params.put("password", pass.getText().toString());
return params;
}
};
Volley.newRequestQueue(Connexion.this).add(stringRequest);
}
}

Error in OTP verification code android

I am Creating an application which perform an OTP verification method..
I implemented the code as described in this link http://www.androidhive.info/2015/08/android-adding-sms-verification-like-whatsapp-part-2/
But when i click the NEXT button in app app is force closing
The function i get error is :
private void requestForSMS(final String name, final String email, final String mobile) {
StringRequest strReq = new StringRequest(Request.Method.POST,
Config.URL_REQUEST_SMS, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject responseObj = new JSONObject(response);
// Parsing json object response
// response will be a json object
boolean error = responseObj.getBoolean("error");
String message = responseObj.getString("message");
// checking for error, if not error SMS is initiated
// device should receive it shortly
if (!error) {
// boolean flag saying device is waiting for sms
pref.setIsWaitingForSms(true);
// moving the screen to next pager item i.e otp screen
viewPager.setCurrentItem(1);
txtEditMobile.setText(pref.getMobileNumber());
layoutEditMobile.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"Error: " + message,
Toast.LENGTH_LONG).show();
}
// hiding the progress bar
progressBar.setVisibility(View.GONE);
} catch (JSONException e) {
//Toast.makeText(getApplicationContext(),"Error: " + e.getMessage(),Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
//Log.e(TAG, "Error: " + error.getMessage());
//Toast.makeText(getApplicationContext(),error.getMessage(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}) {
/**
* Passing user parameters to our server
* #return
*/
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("name", name);
params.put("email", email);
params.put("mobile", mobile);
//Log.e(TAG, "Posting params: " + params.toString());
return params;
}
};
// Adding request to request queue
MyApplication.getInstance().addToRequestQueue(strReq);
}
Log is :
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at com.my.application.activity.SmsActivity.requestForSMS(SmsActivity.java:245)
at com.my.application.activity.SmsActivity.validateForm(SmsActivity.java:157)
at com.my.application.activity.SmsActivity.onClick(SmsActivity.java:117)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17446)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5336)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Volley library is used..
Any help??
public void confirmOTP() throws JSONException {
LayoutInflater lf = LayoutInflater.from(SignUp.this);
View view = lf.inflate(R.layout.confirm_dialog, null);
confirmButton = (Button) view.findViewById(R.id.buttonConfirm);
inputOTP = (EditText) view.findViewById(R.id.editTextOtp);
AlertDialog.Builder dialog = new AlertDialog.Builder(SignUp.this);
dialog.setView(view);
final AlertDialog alertDialog = dialog.create();
alertDialog.show();
alertDialog.setCanceledOnTouchOutside(false);
confirmButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
alertDialog.dismiss();
final ProgressDialog load = ProgressDialog.show(SignUp.this, "Authenticating", "Please Wait ...", false, false);
load.setCanceledOnTouchOutside(false);
final String otp = inputOTP.getText().toString().trim();
StringRequest stringRequest = new StringRequest(Request.Method.POST, ConfingDetalsActivity.CONFIRM_URL, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d("Confirm Response Check>",response.toString());
String mesage;
try {
JSONObject jsonObject=new JSONObject(response);
mesage=jsonObject.getString("msg");
if(mesage.equals("success")){
Toast.makeText(SignUp.this, "Registerd sucessfully", Toast.LENGTH_LONG).show();
load.dismiss();
Intent in = new Intent(SignUp.this, SignupSucess.class);
startActivity(in);
} else {
load.dismiss();
Toast.makeText(SignUp.this, "Wrong OTP Please try again", Toast.LENGTH_SHORT).show();
confirmOTP();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
load.dismiss();
Toast.makeText(SignUp.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
}
) {
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map params = new HashMap();
//Adding the parameters otp and username
params.put(ConfingDetalsActivity.KEY_OTP, otp);
if (businessFrag) {
} else {
params.put(ConfingDetalsActivity.CONSUMER_EMAIL, constant.EMAIl);
}
return params;
}
};
requestQueue.add(stringRequest);
}
});
}
public void register() {
Log.d("RegisterCalled>>>>>>>>>", "register");
final ProgressDialog load = ProgressDialog.show(SignUp.this, "Loading", "Pleas wait...", false, false);
load.setCanceledOnTouchOutside(false);
StringRequest request = new StringRequest(Request.Method.POST, ConfingDetalsActivity.REGISTER_URL, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d("Response Check>>>",response.toString());
load.dismiss();
try {
JSONObject jsonObject = new JSONObject(response);
String message=jsonObject.getString("msg");
if (message.equals("success")) {
confirmOTP();
} else {
Toast.makeText(SignUp.this, "User Name or phone already register", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
load.dismiss();
Toast.makeText(SignUp.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
}) {
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parms = new HashMap<String,String>();
if (businessFrag) {
parms.put(ConfingDetalsActivity.BUSINESS_ZIP_CODE, constant.B_ZIP_CODE);
parms.put(ConfingDetalsActivity.BUSINESS_INDUSTRY, constant.B_INDUSTRY);
parms.put(ConfingDetalsActivity.BUSINESS_PHONE, constant.B_MOBILE);
parms.put(ConfingDetalsActivity.BUSINESS_EMAIL, constant.B_EMAIl);
parms.put(ConfingDetalsActivity.BUSINESS_PASSWORD, constant.B_PASSSOWRD);
parms.put(ConfingDetalsActivity.SIGNUP_TYPE,"1");
} else {
parms.put(ConfingDetalsActivity.CONSUMER_FNAME, constant.F_NAME);
parms.put(ConfingDetalsActivity.CONSUMER_LNAME, constant.L_NAME);
parms.put(ConfingDetalsActivity.CONSUMER_PHONE, constant.MOBILE);
constant.EMAIl);
parms.put(ConfingDetalsActivity.CONSUMER_PASSWORD, constant.PASSSOWRD);
parms.put(ConfingDetalsActivity.SIGNUP_TYPE,"0");
}
return parms;
}
};
requestQueue.add(request);
}

Intent not receive data in second Activity in volley

Hey developers i am tried send the data through intent
i am sending data A activity to B activity data is send A Activity properly but B Activity is not receive but some data is receive but some data not receive
Code is A Activity
private void requestForSMS(final String mobile) {
StringRequest strReq = new StringRequest(Request.Method.POST,
config.Config.URL_REQUEST_SMS, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject responseObj = new JSONObject(response);
final String user = responseObj.getString("uid");
String message = responseObj.getString("msg");
Intent intent1 = new Intent(getApplicationContext(),HttpService.class);
intent1.putExtra("uid", user); // <---Sending data here this data not recive B Activity ------>
Log.d("user id going","====>"+user);
if(!user.equalsIgnoreCase("")){
pref.setIsWaitingForSms(true);
viewPager.setCurrentItem(1);
txtEditMobile.setText(pref.getMobileNumber());
layoutEditMobile.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"ErrorToast: " + message,
Toast.LENGTH_LONG).show();
}
// hiding the progress bar
progressBar.setVisibility(View.GONE);
} catch (JSONException e) {
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "ErrorResponce: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("key","xxxxxxxxxxxxx");
params.put("mobile", mobile);
Log.e(TAG, "Posting params: " + params.toString());
return params;
}
};
int socketTimeout = 60000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
strReq.setRetryPolicy(policy);
// Adding request to request queue
newapp.getInstance().addToRequestQueue(strReq);
}
private void verifyOtp() {
String otp = inputOtp.getText().toString().trim();
if (!otp.isEmpty()) {
Intent grapprIntent = new Intent(getApplicationContext(), HttpService.class);
// <---- sending data here also B Activity---->
grapprIntent.putExtra("key","xxxxxxxxxxxx");
grapprIntent.putExtra("mobileverify", otp);
startService(grapprIntent);
} else {
Toast.makeText(getApplicationContext(), "Please enter the OTP", Toast.LENGTH_SHORT).show();
}
}
private static boolean isValidPhoneNumber(String mobile) {
String regEx = "^[0-9]{10}$";
return mobile.matches(regEx);
}
B Activity
public class HttpService extends IntentService {
private static String TAG = HttpService.class.getSimpleName();
public HttpService() {
super(HttpService.class.getSimpleName());
}
#Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
String otp = intent.getStringExtra("mobileverify");
final String user1 = intent.getStringExtra("uid"); //<---- this is not recive value ---->
verifyOtp(otp,user1);
}
}
/**
* Posting the OTP to server and activating the user
*
* #param otp otp received in the SMS
*/
private void verifyOtp(final String otp, final String user1){
StringRequest strReq = new StringRequest(Request.Method.POST,
config.Config.URL_VERIFY_OTP, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject responseObj = new JSONObject(response);
// Parsing json object response
// response will be a json object
String message = responseObj.getString("msg");
if (message!="") {
// parsing the user profile information
JSONObject profileObj = responseObj.getJSONObject(response);
String mobile = profileObj.getString("mobile");
PrefManager pref = new PrefManager(getApplicationContext());
pref.createLogin(mobile);
Intent intent = new Intent(HttpService.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Toast.makeText(getApplicationContext(), "HTTPIF"+message, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "HTTPELSE"+message, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "HTTPError: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
}
}) {
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("key","xxxxxxxxxx");
params.put("mobileverify", otp);
params.put("uid",user1); // here its given error
Log.e(TAG, "Posting params: " + params.toString());
return params;
}
};
MyApplication.getInstance().addToRequestQueue(strReq);
}
Please Help me Thanks
Your grapprIntentdoesn't contain a value for "uid" key because you don't put it. You use some intent1 which is not used anywhere more. Instead you need to put "uid" into grapprIntent:
grapprIntent.putExtra("uid", user);
Maybe grapprIntent should be global variable for the class or find a way to pass it between methods.
Create A Global variable in your Application class and Use set and get Methods
like this
Application.class
private String user;
public String setuser(String usermy) {
this.user = usermy;
return null;
}
public String getuser()
{
return user;
}
where you want to send value set value like as your code
SMSActivity
MyApplication myUser = (MyApplication)getApplicationContext();
#Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject responseObj = new JSONObject(response);
String user = responseObj.getString("uid");
String user1 = myUser.setuser(user);
And Get Value in your HttpService.class
Like this
MyApplication uidinfo = (MyApplication)getApplicationContext();
final String user = uidinfo.getuser();
and mention manifest.xml inside Application tag
<application
android:name=".MyApplication"
/>
happy coding

Categories

Resources