Hallo,
Ich parse ein XML Dokument von einer IP Adresse und möchte dann einen bestimmten Node ausgeben...
hier mein Code dazu :
String ab="http://xxx.xx.xxx.xxx.xml";
DocumentBuilderFactory factory;
DocumentBuilder builder;
Document doc;
NodeList ndl;
Node node;String text1;
public Nodes() {
try {builder = factory.newDocumentBuilder();
doc = builder.parse(ab);
} catch (Exception e1) {
e1.printStackTrace();
}
ndl = doc.getElementsByTagName("FirstTag");
node = ndl.item(0);
text1 =node.getChildNodes().item(3).getChildNodes().item(1).getNodeName();
}
Alles anzeigen
und so rufe ich das in der onCreate Methode auf
Nodes nod = new Nodes();
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textview = (TextView)findViewById(R.id.textview);
textview.setText(nod.text1);
}
Alles anzeigen
nur bekomme ich immer eine NullPointerException die wie folgt aussieht :
05-11 10:11:28.281: ERROR/AndroidRuntime(451): Uncaught handler: thread main exiting due to uncaught exception
05-11 10:11:28.292: ERROR/AndroidRuntime(451): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test/com.example.test.Testing}: java.lang.NullPointerException
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at android.os.Looper.loop(Looper.java:123)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at android.app.ActivityThread.main(ActivityThread.java:4363)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at java.lang.reflect.Method.invoke(Method.java:521)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-11 10:11:28.292: ERROR/AndroidRuntime(451): at dalvik.system.NativeStart.main(Native Method)
05-11 09:45:47.051: ERROR/AndroidRuntime(425): Caused by: java.lang.NullPointerException
05-11 09:45:47.051: ERROR/AndroidRuntime(425): at com.example.test.Nodes.<init>(Nodes.java:39)
05-11 09:45:47.051: ERROR/AndroidRuntime(425): at com.example.test.Testing.<init>(Testing.java:18)
05-11 09:45:47.051: ERROR/AndroidRuntime(425): at java.lang.Class.newInstanceImpl(Native Method)
05-11 09:45:47.051: ERROR/AndroidRuntime(425): at java.lang.Class.newInstance(Class.java:1479)
05-11 09:45:47.051: ERROR/AndroidRuntime(425): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-11 09:45:47.051: ERROR/AndroidRuntime(425): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
Bei Nodes in Zeile 39 steht :
ndl = doc.getElementsByTagName("FirstTag");
ich habe im Manifest die Permission.INTERNET angegeben.
Ich hoffe jemand kann mir helfen, bitte