I have create an android application where i need to use login. For this i have to parse xml for login. i write the following code under login button.
loginButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
getInput();
parserMethod=new ParserMethod();
login=parserMethod.parseLoginStatus(userName,password,mobileNo,code);
if(login.getLoginStatus().equals("Sucess.."))
{
i=new Intent();
i.setClass(LoginActivity.this, MainActivity.class);
startActivity(i);
}
}
});
public Login parseLoginStatus(String userName, String password,String mobileNo, String code)
{
String sourceString="http://www.example.info/mobapp/Web_service/checkLogin.php?userId=robin&password=123456&mobile=0&code=8080&output=xml";
loadParseData(sourceString);
return MyXMLHandler.login;
}
private void loadParseData(String sourceString)
{
try
{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
URL sourceUrl=new URL(sourceString);
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
}
catch(Exception e)
{
System.out.println("XML Pasing Excpetion = " + e);
}
}
But problem is when the net is not available or the xml is not available then the application crashed . How can i solve the problem. Thanks in advance.