i am trying to implement a login screen where username and password are validated with the help of a rest service.
i have created a global class like this
public class GlobalClass extends Application{
String url="myRestService";
String newURL;
public String getName() {
return url;
}
public void setName(String aName) {
url = aName;
}
public String getNewURL() {
return newURL;
}
public void setNewURL(String bName) {
newURL = bName;
}
}
I have created a screen where the superadmin can change the rest service like
this class is intented to update the rest service
final GlobalClass globalVariable = new GlobalClass();
String restMethod=globalVariable.getName();
et.setText(restMethod);
b= (Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String userEnteredMethod=et.getText().toString();
globalVariable.setNewURL(userEnteredMethod);
Toast.makeText(getApplicationContext(),userEnteredMethod,Toast.LENGTH_SHORT).show();
Intent login=new Intent(getApplicationContext(),Login.class);
startActivity(login);
}
});
Now in my login
i called the global class like this and get the url
final GlobalClass gb = new GlobalClass();
userEnteredMethod = gb.getNewURL();
String newURL = userEnteredMethod.concat("/MethodResult");
AsyncHttpClient client = new AsyncHttpClient();
client.get(newURL, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
try {
JSONObject obj = new JSONObject(response);
if (obj != null) {
JSONArray data = obj.getJSONArray("ValidateSubscriberLoginResult");
for (int i = 0; i < data.length(); i++) {
JSONObject user = data.getJSONObject(i);
if (!user.getString("ID").equals("0")) {
Toast.makeText(getApplicationContext(),"success",Toast.LENGTH_SHORT).show();
} else
{
Toast.makeText(getApplicationContext(),"Check again",Toast.LENGTH_SHORT).show();
}
}
}
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
super.onSuccess(response);
}
on executing the code i'm getting a null pointer exception in String newURL = userEnteredMethod.concat("/MethodResult");
while debuging i found out that i am getting a null value at userEnteredMethod = gb.getNewURL();
please help me to rectify the problem