在我的Android項目當我嘗試連接到follwing網頁, http://familytree-photoalbum.com/android.php?a=login&[email protected]&password=JLjZAT13 和獲取數據解析,..我的申請得到墜毀,不能圖出去,我什麼時候離開。無法連接到XML網頁中,使用SAX解析
這裏是Snipet的解析文件。
case R.id.bSignIn:
String e = email.getText().toString(); // Getting Email from LoginPage
String p = password.getText().toString(); // Getting Password from LoginPage
StringBuilder URL = new StringBuilder(baseURL);
URL.append(e + "&password=" + p);
String fullUrl = URL.toString();
new loadURL().execute(fullUrl);
break;
我的AsyncTask,我使用。
protected class loadURL extends AsyncTask<String, Void, Intent> {
protected Intent doInBackground(String... fullUrl) {
return xmlParsing(fullUrl[0]);
}
protected void onPostExecute(Intent intent) {
startActivity(intent);
startActivity(new Intent(LoginPage.this, InvalidUser.class));
}
}
這裏xmlParsing方法,是從我的AsyncTask稱爲
protected Intent xmlParsing(String url) {
Intent activity = new Intent();
try {
URL loginPage = new URL(url);
// Getting XML Reader
/**
* The parse() method of SAXParser class reads the contents. The
* SAXParserFactory is a factory API that enables applications to
* configure and obtain a SAX parser to parse XML documents. The
* startElement() method retrieves all starting elements and prints
* them on the console. Whenever an error occurs it throws the
* SAXException.
*/
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
HandlingLoginPage doingWork = new HandlingLoginPage();
xr.setContentHandler(doingWork);
xr.parse(new InputSource(loginPage.openStream()));
Log.i("info", doingWork.code());
if ((doingWork.userInformation()) == true) {
activity = new Intent(LoginPage.this, HomeScreen.class);
} else
activity = new Intent(LoginPage.this, InvalidUser.class);
} catch (Exception e1) {
e1.printStackTrace();
title.setText("Error");
}
return activity;
}
這裏是一個名爲HandlingLoginPage.class
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import android.content.Intent;
public class HandlingLoginPage extends DefaultHandler {
String defineCode = null;
boolean user = false;
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (localName.equals("code")) {
defineCode = attributes.getValue("data");
if (defineCode.equals("IP")) {
user = false;
} else if (defineCode.equals("LS"))
user = true;
}
}
protected boolean userInformation(){
return user;
}
}
你是否在ui線程中執行所有這些操作? –
Sory爲最近回覆,我有一些互聯網問題@RoyJamesSchumacher,是的,我是一個初學者,...和我的合作伙伴,誰是PHP的專家,幫助我,..我得到的問題是,我不能連接到網站。 – asadnwfp
更多的是,我從新波士頓提供的視頻中學習了這種技術。 [鏈接](http://thenewboston.org/watch.php?cat=6&number=156) – asadnwfp