天气预报API地址:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=beijing
<?xml version="1.0" encoding="utf-8" ?> - <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">
<string>直辖市</string>
<string>北京</string>
<string>54511</string>
。。。。。
</ArrayOfString>
整个天气预报的XML只有一个<string>元素,代码看了很久感觉没什么问题,onclick后报异常。后来单步调试运行发现 执行完第一次startElement后立马就报错了。DEBUG视图 弹出一个ExpatParser.startElement(。。。)的标签页 内部标注了一行文本“Source not found.”
我这个代码应该怎么改~~真心不知道怎么办了
WeatherReport.java
=================
public class WeatherReport extends Activity implements OnClickListener {
private static final String WEATHER_API_URL = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=";
private static final String NETWORK_ERROR = "网络异常";
private EditText weather_city_edit;
private Button goQuery;
private TextView city;
private TextView weather;
private TextView wendu;
private ImageView imgweather;
private String info="info";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
city=(TextView) findViewById(R.id.city);
weather=(TextView) findViewById(R.id.weather);
wendu=(TextView) findViewById(R.id.wendu);
imgweather=(ImageView) findViewById(R.id.imgweather);
weather_city_edit = (EditText) findViewById(R.id.weather_city_edit);
goQuery = (Button) findViewById(R.id.goQuery);
goQuery.setOnClickListener(this);
}
public void onClick(View v) {
// 获得用户输入的城市名称
Log.i(info,"onClick");
String cityname = weather_city_edit.getText().toString().trim();
String resultStr=WEATHER_API_URL + cityname;
try {
// 构建SAXParser
URL url = new URL(resultStr);
javaBean javabean=new javaBean();
System.out.println(resultStr);
SAXParserFactory factory = SAXParserFactory.newInstance(); //创建一个SAX工厂
SAXParser parser = factory.newSAXParser();