As i am new to android development i am struck up with a problem in my project. Code is..
for processing webservice code i am calling webinterface class from main.java file as follows.
Main.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
WebServiceInterface webinterface= new WebServiceInterface();
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
getuser = username.getText().toString();
getpass = password.getText().toString();
HashMap<String, Object> map = new HashMap<String,Object>();
map.put("username", getuser);
map.put("password", getpass);
webinterface.sendRequest(map);
}
});
In Webinterface class i am receiving the following map values & converting them to string & send to RestClient.class to process webservice request..
WebServiceInterface.java
ArrayList<String> ast = new ArrayList<String>();
Collection<Object> strings = map.values();
Iterator iterator = strings.iterator();
while (iterator.hasNext()) {
getuser = (String) iterator.next();
ast.add(getuser);
}
String password = ast.get(0).toString();
String username = ast.get(1).toString();
RestClient client = new RestClient(
"***********************");
client.AddParam("username", username);
client.AddParam("password", password);
try {
client.Execute(RequestMethod.POST);
} catch (Exception e) {
e.printStackTrace();
}
String response = client.getResponse();
/** here getting response & sending that response back to Main.java class**/
Main main = new Main();
main.responseData(responsedata);
here after receiving response method from interface class the following process is going on in Main.java class
Main.java
@Override
public void onCreate(Bundle savedInstanceState) {
System.out.println("response is----^^^^^^^^^^====>>>>>> " + getrespstatus + "_______---->> > " + respdoctorID);
}//end of oncreate...
public void responseData(HashMap<String, Object> responsedata) {
// TODO Auto-generated method stub
System.out.println("response data in main class->>>>>>>> " + responsedata);
Collection<Object> strings = responsedata.values();
Iterator iterator = strings.iterator();
while (iterator.hasNext()) {
getresponse = (String) iterator.next();
ast.add(getresponse);
}
String status = ast.get(0).toString();
try {
JSONObject json = new JSONObject(status);
getrespstatus = json.getString("status");
respdoctorID = json.getString("doctorID");
callmethod(getrespstatus, respdoctorID);
System.out.println("response is----^^^^^^^^^^====>>>>>> " + getrespstatus + "_______---->> > " + respdoctorID);
/* if(getrespstatus == "true")
{
startActivity(new Intent(Main.this,Second.class))
}else
{
//some alert message
}*/
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
here if response status== true, i want to start activity. but here i am getting error as null pointer exception.. And my other doubt is here i am getting response & doctorID. if i am trying to access the following values in oncreate method, it showing as null values (simply to say if i am printing response values in log, in responseData method i am getting, if printing from oncreate getting null values) So, can anyone help me with this...