數據`下一個代碼應該從baseURL時(網絡服務)收杆數據的TextView 問題: * 它給IOException異常..我從web服務,但該程序仍肯定給出錯誤任何一個幫助從Web服務獲取數據? *獲得從WebService IOException異常
public class NewParsActivity extends Activity {
/** Called when the activity is first created. */
static final String baseUrl="http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml";
TextView tv;
EditText ed,ed2;
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.text);
ed=(EditText)findViewById(R.id.edt);
b=(Button) findViewById(R.id.button1);
ed2=(EditText) findViewById(R.id.editText1);
try{
SAXParserFactory spf=SAXParserFactory.newInstance();
SAXParser sp=spf.newSAXParser();
XMLReader xr=sp.getXMLReader();
URL link=new URL(baseUrl);
handlXml doingWork=new handlXml();
xr.setContentHandler(doingWork);
xr.parse(new InputSource(link.openStream()));
String information=doingWork.getInformation();
tv.setText(information);
}catch(Exception e){
tv.setText("Error");
}
//
public class handlXml extends DefaultHandler {
One item=new One();
public String getInformation(){
return item.DataToString();
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
if(localName.equals("website")){
String uniN=attributes.getValue("category");
item.setName(uniN);
}
}
}
//
<i>
public class One {
String UName;
public void setName(String n){
UName=n;
}
public String DataToString()
{
return "In"+UName;
}
}
<i>
安置自己的logcat這裏 – Praveenkumar
什麼錯誤???? – Rajnikant
其中是endElement,字符.. – Nikhil