一个问题不知什么原因,代码:
1 public class OtherActivity extends ListActivity { 2 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 //setContentView(R.layout.activity_other); 7 8 //TextView tv1 = (TextView) findViewById(R.id.editText1); 9 //获取存入的xml字符串 10 String PaiMaiXML=load(); 11 List<String> data = new ArrayList<String>(); 12 data.add("车牌列表"); 13 14 List<Map<String, Object>> PaiMaiList = new ArrayList<Map<String, Object>>(); 15 Map<String, Object> PaiMaiMap = new HashMap<String, Object>(); 16 17 ByteArrayInputStream tInputStringStream = null; 18 try 19 { 20 if (PaiMaiXML != null && !PaiMaiXML.trim().equals("")) { 21 tInputStringStream = new ByteArrayInputStream(PaiMaiXML.getBytes()); 22 } 23 } 24 catch (Exception e) { 25 // TODO: handle exception 26 //tv1.setText(e.getMessage()); 27 return; 28 } 29 XmlPullParser parser = Xml.newPullParser(); 30 try { 31 parser.setInput(tInputStringStream, "UTF-8"); 32 int eventType = parser.getEventType(); 33 34 //List<PaiMaiInfo> PaiMaiList=new ArrayList<PaiMaiInfo>; 35 36 while (eventType != XmlPullParser.END_DOCUMENT) { 37 switch (eventType) { 38 case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理 39 // persons = new ArrayList<Person>(); 40 break; 41 case XmlPullParser.START_TAG:// 开始元素事件 42 String name = parser.getName(); 43 44 if (name.equalsIgnoreCase("Base_tabletNumber")) { 45 // currentPerson = new Person(); 46 // currentPerson.setId(new 47 // Integer(parser.getAttributeValue(null, "id"))); 48 49 //tv1.setText(parser.nextText()); 50 PaiMaiMap.put("title", parser.nextText()); 51 data.add(parser.nextText()); 52 53 } 54 if(name.equalsIgnoreCase("Base_Family")) 55 { 56 PaiMaiMap.put("info", parser.nextText()); 57 PaiMaiMap.put("img", R.drawable.ic_launcher); 58 PaiMaiList.add(PaiMaiMap); 59 PaiMaiMap = new HashMap<String, Object>(); 60 } 61 // else if (currentPerson != null) { 62 // if (name.equalsIgnoreCase("loginlink")) { 63 // currentPerson.setName(parser.nextText());// 如果后面是Text节点,即返回它的值 64 // } else if (name.equalsIgnoreCase("errmsg")) { 65 // currentPerson.setAge(new Short(parser.nextText())); 66 // } 67 // } 68 break; 69 case XmlPullParser.END_TAG:// 结束元素事件 70 // if (parser.getName().equalsIgnoreCase("person") 71 // && currentPerson != null) { 72 // persons.add(currentPerson); 73 // currentPerson = null; 74 // } 75 break; 76 } 77 eventType = parser.next(); 78 79 } 80 tInputStringStream.close(); 81 // return persons; 82 } catch (XmlPullParserException e) { 83 // TODO Auto-generated catch block 84 e.printStackTrace(); 85 } catch (IOException e) { 86 // TODO Auto-generated catch block 87 e.printStackTrace(); 88 } 89 //ListView listView = (ListView) findViewById(R.id.listView1); 90 //listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data)); 91 //setContentView(listView); 92 SimpleAdapter adapter = new SimpleAdapter(this,PaiMaiList,R.layout.listcell, 93 new String[]{"title","info","img"}, 94 new int[]{R.id.title,R.id.info,R.id.img}); 95 setListAdapter(adapter); 96 97 }
当我把51行的注释掉就可以了,求真相
改成String wee=parser.nextText(); 也是有问题,难道nextText()的原因。。。
nextText()不能重复执行,具体原因 再研究