我有这个简单的XMLPullparser代码,该代码每次都能正常工作并成功获取数据,但是每当我添加简单的代码行以查看日志时,“应用程序”屏幕都会变为空白。
这是我的代码,
try {
XmlPullParserFactory factory;
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
URL url = new URL(XML_URL[position]);
xpp.setInput(url.openConnection().getInputStream(), "UTF_8");
int eventType = xpp.getEventType();
boolean insideItem = false;
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase("channel")) {
insideItem = true;
} else if (xpp.getName().equalsIgnoreCase("title")) {
if (insideItem) {
holdData.add(xpp.nextText());
//Log.e(TAG,xpp.nextText());
}
}
}
eventType = xpp.next();
}
}
在上面的代码中,如果我取消注释
Log.e(TAG,xpp.nextText());
行,则App屏幕将变为空白,Logcat将显示此错误。09-30 21:38:59.940: E/vinput-seamless(103): found PS2 device
09-30 21:38:59.940: E/vinput-seamless(103): found seamless mouse device
09-30 21:38:59.940: E/vinput-seamless(103): --------- beginning of /dev/log/system
09-30 21:39:01.788: E/BandwidthController(108): runIptablesCmd(): failed /system/bin/iptables -t raw -N bw_raw_PREROUTING res=768
09-30 21:39:01.788: E/BandwidthController(108): runIptablesCmd(): failed /system/bin/ip6tables -t raw -N bw_raw_PREROUTING res=768
09-30 21:39:01.852: E/BandwidthController(108): runIptablesCmd(): failed /system/bin/iptables -t raw -A bw_raw_PREROUTING ! -i lo+ -m owner --socket-exists res=768
09-30 21:39:01.852: E/BandwidthController(108): runIptablesCmd(): failed /system/bin/ip6tables -t raw -A bw_raw_PREROUTING ! -i lo+ -m owner --socket-exists res=768
09-30 21:39:03.108: E/setdpi(297): Setting DPI to 240
09-30 21:39:03.288: E/SurfaceFlinger(111): setOrientation with orientation=0
09-30 21:39:03.288: E/SurfaceFlinger(111): setOrientation orientation=0
09-30 21:39:03.288: E/FramebufferNativeWindow(111): setOrientation with fbDev=0xb7c49af0 fbDev->setOrientation=0xb600bf20 orientation=0
09-30 21:39:03.400: E/Trace(111): error opening trace file: No such file or directory (2)
09-30 21:39:03.408: E/Trace(304): error opening trace file: No such file or directory (2)
09-30 21:39:05.964: E/PhonePolicy(112): Could not preload class for phone policy: com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback
09-30 21:39:06.936: E/Genymotion(337): usbOnlinePath not found
09-30 21:39:06.936: E/Genymotion(337): batteryHealthPath not found
09-30 21:39:06.936: E/Genymotion(337): batteryTemperaturePath not found
09-30 21:39:09.836: E/libsuspend(337): Error opening /sys/power/autosleep: No such file or directory
09-30 21:39:09.836: E/libsuspend(337): Error opening /sys/power/wakeup_count: Permission denied
09-30 21:39:09.836: E/libsuspend(337): failed to initialize autosuspend
09-30 21:39:09.936: E/WVMExtractor(114): Failed to open libwvm.so
09-30 21:39:09.936: E/Trace(114): error opening trace file: No such file or directory (2)
09-30 21:39:09.960: E/EventHub(337): could not get driver version for /dev/input/mouse3, Not a typewriter
09-30 21:39:09.964: E/WVMExtractor(114): Failed to open libwvm.so
09-30 21:39:09.976: E/EventHub(337): could not get driver version for /dev/input/mouse2, Not a typewriter
09-30 21:39:09.992: E/EventHub(337): could not get driver version for /dev/input/mouse1, Not a typewriter
09-30 21:39:10.016: E/EventHub(337): could not get driver version for /dev/input/mouse0, Not a typewriter
09-30 21:39:10.060: E/Trace(337): error opening trace file: No such file or directory (2)
09-30 21:39:10.068: E/EventHub(337): could not get driver version for /dev/input/mice, Not a typewriter
09-30 21:39:10.148: E/ConnectivityService(337): Ignoring protectedNetwork 10
09-30 21:39:10.148: E/ConnectivityService(337): Ignoring protectedNetwork 11
09-30 21:39:10.148: E/ConnectivityService(337): Ignoring protectedNetwork 12
09-30 21:39:10.152: E/WifiStateMachine(337): Failed to reload STA firmware java.lang.IllegalStateException: command '2 softap fwreload eth1 STA' failed with '400 2 Softap operation failed (Success)'
09-30 21:39:10.156: E/CommandListener(108): Failed to open /proc/sys/net/ipv6/conf/eth1/use_tempaddr: No such file or directory
09-30 21:39:10.156: E/WifiStateMachine(337): Unable to change interface settings: java.lang.IllegalStateException: command '5 interface ipv6privacyextensions eth1 enable' failed with '400 5 Failed to set ipv6 privacy extensions (No such file or directory)'
09-30 21:39:10.332: E/WifiConfigStore(337): Error parsing configurationjava.io.FileNotFoundException: /data/misc/wifi/ipconfig.txt: open failed: ENOENT (No such file or directory)
09-30 21:39:10.332: E/wpa_supplicant(405): Line -1: too long model_name (len=41 max_len=32)
09-30 21:39:10.332: E/wpa_supplicant(405): Line -1: failed to parse 'model_name=Google Nexus S - 4.1.1 - API 16 - 480x800'.
09-30 21:39:10.332: E/WifiStateMachine(337): Failed to set model name Google Nexus S - 4.1.1 - API 16 - 480x800
09-30 21:39:10.332: E/wpa_supplicant(405): Line -1: too long model_number (len=41 max_len=32)
09-30 21:39:10.332: E/wpa_supplicant(405): Line -1: failed to parse 'model_number=Google Nexus S - 4.1.1 - API 16 - 480x800'.
09-30 21:39:10.332: E/WifiStateMachine(337): Failed to set model number Google Nexus S - 4.1.1 - API 16 - 480x800
09-30 21:39:10.336: E/WifiStateMachine(337): Failed to set frequency band 0
09-30 21:39:10.484: E/Trace(411): error opening trace file: No such file or directory (2)
09-30 21:39:10.544: E/BandwidthController(108): runIptablesCmd(): failed /system/bin/iptables -t raw -A bw_raw_PREROUTING ! -i lo+ -m owner --socket-exists res=768
09-30 21:39:10.548: E/BandwidthController(108): runIptablesCmd(): failed /system/bin/ip6tables -t raw -A bw_raw_PREROUTING ! -i lo+ -m owner --socket-exists res=768
09-30 21:39:10.548: A/NetworkManagementService(337): problem enabling bandwidth controls
09-30 21:39:10.548: A/NetworkManagementService(337): com.android.server.NativeDaemonConnector$NativeDaemonFailureException: command '6 bandwidth enable' failed with '400 6 Bandwidth command failed'
09-30 21:39:10.548: A/NetworkManagementService(337): at com.android.server.NativeDaemonConnector.execute(NativeDaemonConnector.java:345)
09-30 21:39:10.548: A/NetworkManagementService(337): at com.android.server.NativeDaemonConnector.executeForList(NativeDaemonConnector.java:282)
09-30 21:39:10.548: A/NetworkManagementService(337): at com.android.server.NativeDaemonConnector.execute(NativeDaemonConnector.java:248)
09-30 21:39:10.548: A/NetworkManagementService(337): at com.android.server.NetworkManagementService.prepareNativeDaemon(NetworkManagementService.java:292)
09-30 21:39:10.548: A/NetworkManagementService(337): at com.android.server.NetworkManagementService.systemReady(NetworkManagementService.java:188)
09-30 21:39:10.548: A/NetworkManagementService(337): at com.android.server.ServerThread$1.run(SystemServer.java:779)
09-30 21:39:10.548: A/NetworkManagementService(337): at com.android.server.am.ActivityManagerService.systemReady(ActivityManagerService.java:7617)
09-30 21:39:10.548: A/NetworkManagementService(337): at com.android.server.ServerThread.run(SystemServer.java:768)
09-30 21:39:10.820: E/Trace(503): error opening trace file: No such file or directory (2)
09-30 21:39:10.944: E/Trace(534): error opening trace file: No such file or directory (2)
09-30 21:39:10.944: E/jdwp(534): Failed sending reply to debugger: Broken pipe
09-30 21:39:10.944: E/Trace(523): error opening trace file: No such file or directory (2)
09-30 21:39:11.096: E/GpsLocationProvider(337): no AGPS interface in agps_data_conn_open
09-30 21:39:11.100: E/BinaryDictionaryGetter(503): Could not find a dictionary pack
09-30 21:39:11.100: E/ActivityThread(503): Failed to find provider info for com.android.inputmethod.latin.dictionarypack
09-30 21:39:11.116: E/Trace(568): error opening trace file: No such file or directory (2)
09-30 21:39:11.140: E/Trace(587): error opening trace file: No such file or directory (2)
09-30 21:39:11.172: E/Trace(605): error opening trace file: No such file or directory (2)
09-30 21:39:13.004: E/Trace(642): error opening trace file: No such file or directory (2)
09-30 21:39:13.140: E/WVMExtractor(114): Failed to open libwvm.so
09-30 21:39:13.176: E/WVMExtractor(114): Failed to open libwvm.so
09-30 21:39:13.188: E/Trace(656): error opening trace file: No such file or directory (2)
09-30 21:39:13.220: E/WVMExtractor(114): Failed to open libwvm.so
09-30 21:39:13.244: E/WVMExtractor(114): Failed to open libwvm.so
09-30 21:39:13.264: E/WVMExtractor(114): Failed to open libwvm.so
09-30 21:39:13.312: E/jdwp(696): Failed sending reply to debugger: Broken pipe
09-30 21:39:13.312: E/Trace(696): error opening trace file: No such file or directory (2)
09-30 21:39:13.332: E/Trace(708): error opening trace file: No such file or directory (2)
09-30 21:39:13.788: E/Trace(734): error opening trace file: No such file or directory (2)
09-30 21:39:14.024: E/Trace(750): error opening trace file: No such file or directory (2)
09-30 21:39:14.160: E/Trace(767): error opening trace file: No such file or directory (2)
09-30 21:39:20.576: E/Trace(809): error opening trace file: No such file or directory (2)
09-30 21:39:20.732: E/Trace(824): error opening trace file: No such file or directory (2)
09-30 21:39:39.912: E/Trace(864): error opening trace file: No such file or directory (2)
09-30 21:39:40.420: E/Trace(881): error opening trace file: No such file or directory (2)
09-30 21:39:40.492: E/Trace(897): error opening trace file: No such file or directory (2)
09-30 21:39:40.544: E/Trace(911): error opening trace file: No such file or directory (2)
09-30 21:39:40.620: E/Trace(925): error opening trace file: No such file or directory (2)
09-30 21:39:40.640: E/Trace(938): error opening trace file: No such file or directory (2)
09-30 21:39:40.856: E/SocketStream(111): readFully was waiting for 403440 bytes, got 7300
09-30 21:39:40.856: E/SocketStream(111): readFully was waiting for 396140 bytes, got 11680
09-30 21:39:40.856: E/SocketStream(111): readFully was waiting for 384460 bytes, got 16384
09-30 21:39:40.856: E/SocketStream(111): readFully was waiting for 368076 bytes, got 14276
09-30 21:39:40.856: E/SocketStream(111): readFully was waiting for 353800 bytes, got 16384
09-30 21:39:40.860: E/SocketStream(111): readFully was waiting for 337416 bytes, got 17196
09-30 21:39:40.860: E/SocketStream(111): readFully was waiting for 320220 bytes, got 16384
09-30 21:39:40.860: E/SocketStream(111): readFully was waiting for 303836 bytes, got 16384
09-30 21:39:40.860: E/SocketStream(111): readFully was waiting for 287452 bytes, got 6652
09-30 21:39:40.864: E/SocketStream(111): readFully was waiting for 280800 bytes, got 32768
09-30 21:39:40.864: E/SocketStream(111): readFully was waiting for 248032 bytes, got 8112
09-30 21:39:40.864: E/SocketStream(111): readFully was waiting for 239920 bytes, got 49152
09-30 21:39:40.864: E/SocketStream(111): readFully was waiting for 190768 bytes, got 16384
09-30 21:39:40.864: E/SocketStream(111): readFully was waiting for 174384 bytes, got 13304
09-30 21:39:40.868: E/SocketStream(111): readFully was waiting for 161080 bytes, got 49152
09-30 21:39:40.868: E/SocketStream(111): readFully was waiting for 111928 bytes, got 15088
09-30 21:39:40.868: E/SocketStream(111): readFully was waiting for 96840 bytes, got 49152
09-30 21:39:40.868: E/SocketStream(111): readFully was waiting for 47688 bytes, got 16384
09-30 21:39:40.868: E/SocketStream(111): readFully was waiting for 31304 bytes, got 1624
09-30 21:39:40.868: E/SocketStream(111): readFully was waiting for 29680 bytes, got 16384
09-30 21:39:40.928: E/Trace(965): error opening trace file: No such file or directory (2)
09-30 21:41:15.460: E/InputDispatcher(337): channel '535ebd3c com.news.securitynews/com.news.securitynews.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
09-30 21:41:16.308: E/SocketStream(111): readFully was waiting for 403440 bytes, got 49152
09-30 21:41:16.308: E/SocketStream(111): readFully was waiting for 354288 bytes, got 15088
09-30 21:41:16.308: E/SocketStream(111): readFully was waiting for 339200 bytes, got 49152
09-30 21:41:16.308: E/SocketStream(111): readFully was waiting for 290048 bytes, got 15088
09-30 21:41:16.308: E/SocketStream(111): readFully was waiting for 274960 bytes, got 49152
09-30 21:41:16.308: E/SocketStream(111): readFully was waiting for 225808 bytes, got 15088
09-30 21:41:16.308: E/SocketStream(111): readFully was waiting for 210720 bytes, got 49152
09-30 21:41:16.312: E/SocketStream(111): readFully was waiting for 161568 bytes, got 16384
09-30 21:41:16.312: E/SocketStream(111): readFully was waiting for 145184 bytes, got 1624
09-30 21:41:16.312: E/SocketStream(111): readFully was waiting for 143560 bytes, got 49152
09-30 21:41:16.312: E/SocketStream(111): readFully was waiting for 94408 bytes, got 16384
09-30 21:41:16.312: E/SocketStream(111): readFully was waiting for 78024 bytes, got 1624
09-30 21:41:16.316: E/SocketStream(111): readFully was waiting for 76400 bytes, got 49152
09-30 21:41:16.316: E/SocketStream(111): readFully was waiting for 27248 bytes, got 16384
09-30 21:41:16.356: E/Trace(1018): error opening trace file: No such file or directory (2)
但是,如果删除此行,我可以看到日志数据,
holdData.add(xpp.nextText());
简而言之,
我不能同时使用这两行,也不知道为什么会这样?
// These two lines doesn't work when use together, however they work individually
holdData.add(xpp.nextText());
Log.e(TAG,xpp.nextText());
这是某种内存错误还是什么?
最佳答案
您在xpp上调用了两次nextText()方法,我认为这不是您想要的。
相反,只需执行以下操作:
String nextText = xpp.nextText();
holdData.add(nextText);
Log.e(TAG, nextText);