我基本上使用开发人员培训课程(培训)的源代码。我尝试将 RSS 提要读入带有动态 UI 的 Android 中,并带有像 src 这样的片段。并在 MainActivity 中使用新线程来分阶段 .XML。这是我使用的代码。(代码)
我更改数据类型:
public class RSSData {
// public static String[] Headlines = new String[20];
public static List<String> Headlines = new ArrayList<String>();
// public static String[] Articles = new String[20];
public static List<String> Articles = new ArrayList<String>();
}
有时效果很好。但是在触摸 headers_fragment 的列表项时经常崩溃。所以我无法阅读其中的详细文章。
这是logcat:
03-16 17:19:43.102: E/InputEventReceiver(12106): Exception dispatching input event.
03-16 17:19:43.102: E/MessageQueue-JNI(12106): Exception in MessageQueue callback: handleReceiveCallback
03-16 17:19:43.132: E/MessageQueue-JNI(12106): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(16908298, class android.widget.ListView) with Adapter(class android.widget.ArrayAdapter)]
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.widget.ListView.layoutChildren(ListView.java:1544)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3953)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.View.dispatchTouchEvent(View.java:7350)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2412)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2147)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2139)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1476)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.app.Activity.dispatchTouchEvent(Activity.java:2487)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2087)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.View.dispatchPointerEvent(View.java:7535)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3415)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3347)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4456)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4434)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4538)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.os.MessageQueue.nativePollOnce(Native Method)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.os.MessageQueue.next(MessageQueue.java:125)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.os.Looper.loop(Looper.java:124)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at android.app.ActivityThread.main(ActivityThread.java:4921)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at java.lang.reflect.Method.invokeNative(Native Method)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at java.lang.reflect.Method.invoke(Method.java:511)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
03-16 17:19:43.132: E/MessageQueue-JNI(12106): at dalvik.system.NativeStart.main(Native Method)
03-16 17:19:43.147: D/AndroidRuntime(12106): Shutting down VM
03-16 17:19:43.147: W/dalvikvm(12106): threadid=1: thread exiting with uncaught exception (group=0x41b212a0)
03-16 17:19:43.177: E/AndroidRuntime(12106): FATAL EXCEPTION: main
03-16 17:19:43.177: E/AndroidRuntime(12106): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(16908298, class android.widget.ListView) with Adapter(class android.widget.ArrayAdapter)]
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.widget.ListView.layoutChildren(ListView.java:1544)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3953)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.View.dispatchTouchEvent(View.java:7350)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2412)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2147)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2161)
03-16 17:19:43.177: E/AndroidRuntime(12106): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2139)
03-16 17:19:43.177: E/AndroidRuntime(12106): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1476)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.app.Activity.dispatchTouchEvent(Activity.java:2487)
03-16 17:19:43.177: E/AndroidRuntime(12106): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2087)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.View.dispatchPointerEvent(View.java:7535)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3415)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3347)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4456)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4434)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4538)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.os.MessageQueue.nativePollOnce(Native Method)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.os.MessageQueue.next(MessageQueue.java:125)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.os.Looper.loop(Looper.java:124)
03-16 17:19:43.177: E/AndroidRuntime(12106): at android.app.ActivityThread.main(ActivityThread.java:4921)
03-16 17:19:43.177: E/AndroidRuntime(12106): at java.lang.reflect.Method.invokeNative(Native Method)
03-16 17:19:43.177: E/AndroidRuntime(12106): at java.lang.reflect.Method.invoke(Method.java:511)
03-16 17:19:43.177: E/AndroidRuntime(12106): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
03-16 17:19:43.177: E/AndroidRuntime(12106): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)