1
解析XML代碼得到的例外是我在安卓
/// Element rootelement = doc.getDocumentElement();
XPathFactory xpathfactory = XPathFactory.newInstance();
XPath xpath = xpathfactory.newXPath();
try {
xpathexpression = xpath.compile("//@*[name()='diffgr:id']");
result = xpathexpression.evaluate(doc,XPathConstants.NODESET);
Log.v(result.toString(), "Value of result");
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
NodeList nodelist =(NodeList) result;
Node childlist = null;
// org.w3c.dom.Element rootelement = doc.getDocumentElement();
// NodeList nl = rootelement.getChildNodes();
Log.v(new Integer(nodelist.getLength()).toString(), "Lenght of node list");
for (int i =0; i< nodelist.getLength(); i++)
{
Node n = nodelist.item(i);
System.out.println("message");
childlist = n.getFirstChild();
System.out.println("message2");
String s = childlist.getNodeValue(); // THIS LINE GIVES EXCEPTION ELSE CODE IS CORRECT
異常升高是休耕
11-22 21:50:58.166: E/AndroidRuntime(1123): FATAL EXCEPTION: main
11-22 21:50:58.166: E/AndroidRuntime(1123): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.axml/com.example.axml.MainActivity}: java.lang.NullPointerException
11-22 21:50:58.166: E/AndroidRuntime(1123): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-22 21:50:58.166: E/AndroidRuntime(1123): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-22 21:50:58.166: E/AndroidRuntime(1123): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-22 21:50:58.166: E/AndroidRuntime(1123): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-22 21:50:58.166: E/AndroidRuntime(1123): at android.os.Handler.dispatchMessage(Handler.java:99)
11-22 21:50:58.166: E/AndroidRuntime(1123): at android.os.Looper.loop(Looper.java:123)
11-22 21:50:58.166: E/AndroidRuntime(1123): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-22 21:50:58.166: E/AndroidRuntime(1123): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 21:50:58.166: E/AndroidRuntime(1123): at java.lang.reflect.Method.invoke(Method.java:521)
11-22 21:50:58.166: E/AndroidRuntime(1123): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-22 21:50:58.166: E/AndroidRuntime(1123): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-22 21:50:58.166: E/AndroidRuntime(1123): at dalvik.system.NativeStart.main(Native Method)
11-22 21:50:58.166: E/AndroidRuntime(1123): Caused by: java.lang.NullPointerException
11-22 21:50:58.166: E/AndroidRuntime(1123): at com.example.axml.MainActivity.onCreate(MainActivity.java:92)
11-22 21:50:58.166: E/AndroidRuntime(1123): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-22 21:50:58.166: E/AndroidRuntime(1123): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2 627)
11-22 21:50:58.166: E/AndroidRuntime(1123): ... 11 more
11-22 21:50:58.186: W/ActivityManager(58): Force finishing activity com.example.axml/.MainActivity
11-22 21:50:58.697: W/ActivityManager(58): Activity pause timeout for HistoryRecord{44f68330 com.example.axml/.MainActivity}
11-22 21:51:05.305: D/dalvikvm(288): GC_EXPLICIT freed 29 objects/1416 bytes in 131ms