通过解析我的智能手机的SD卡上的xml文件,我遇到了一些问题。
xml结构看起来像:
....
<nd ref="1364745028"/>
<nd ref="1364745137"/>
<nd ref="2121048622"/>
<nd ref="2121048651"/>
<tag v="forest" k="landuse"/>
</way>
-<way id="25089587">
<nd ref="273065498"/>
<nd ref="273065777"/>
<nd ref="1882290182"/>
<nd ref="1882290194"/>
....
我特别想要“森林”的价值。我怎样才能获得价值? 我目前的代码如下:
....
try {
File root = android.os.Enviroment.getExternalStorageDirectory();
Document document = builder.parse(new FileInputStream(root.getAbsolutePath() + "/xmls/xapi.xml");
NodeList tag = document.getElementsByTagName("tag");
for(int i = 0; i < tag.getLength(); i++) {
Element element = (Element) tag.item(i);
NodeList value = element.getElementsByTagName("k");
Element line = (Element) value.item(0);
parameter.setText(line.getTextContent());
}
}catch(SAXException e) {
....
}catch(IOException e) {
....
}
当我点击一个按钮时,应用程序会崩溃,其中onlick-method就是这些try-catch块。任何一个意识形态,如何解决它?提前谢谢。
EDIT1 错误信息
02-20 17:54:42.495: E/AndroidRuntime(12627): FATAL EXCEPTION: main
02-20 17:54:42.495: E/AndroidRuntime(12627): java.lang.IllegalStateException: Could not execute method of the activity
02-20 17:54:42.495: E/AndroidRuntime(12627): at android.view.View$1.onClick(View.java:3100)
02-20 17:54:42.495: E/AndroidRuntime(12627): at android.view.View.performClick(View.java:3627)
02-20 17:54:42.495: E/AndroidRuntime(12627): at android.view.View$PerformClick.run(View.java:14329)
02-20 17:54:42.495: E/AndroidRuntime(12627): at android.os.Handler.handleCallback(Handler.java:605)
02-20 17:54:42.495: E/AndroidRuntime(12627): at android.os.Handler.dispatchMessage(Handler.java:92)
02-20 17:54:42.495: E/AndroidRuntime(12627): at android.os.Looper.loop(Looper.java:137)
02-20 17:54:42.495: E/AndroidRuntime(12627): at android.app.ActivityThread.main(ActivityThread.java:4511)
02-20 17:54:42.495: E/AndroidRuntime(12627): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 17:54:42.495: E/AndroidRuntime(12627): at java.lang.reflect.Method.invoke(Method.java:511)
02-20 17:54:42.495: E/AndroidRuntime(12627): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
02-20 17:54:42.495: E/AndroidRuntime(12627): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
02-20 17:54:42.495: E/AndroidRuntime(12627): at dalvik.system.NativeStart.main(Native Method)
02-20 17:54:42.495: E/AndroidRuntime(12627): Caused by: java.lang.reflect.InvocationTargetException
02-20 17:54:42.495: E/AndroidRuntime(12627): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 17:54:42.495: E/AndroidRuntime(12627): at java.lang.reflect.Method.invoke(Method.java:511)
02-20 17:54:42.495: E/AndroidRuntime(12627): at android.view.View$1.onClick(View.java:3095)
02-20 17:54:42.495: E/AndroidRuntime(12627): ... 11 more
02-20 17:54:42.495: E/AndroidRuntime(12627): Caused by: java.lang.NullPointerException
02-20 17:54:42.495: E/AndroidRuntime(12627): at com.example.parsexml.MainActivity.ReadXMLFromSD(MainActivity.java:116)
02-20 17:54:42.495: E/AndroidRuntime(12627): ... 14 more