PubNub 订阅回调错误
PubNub SubscribeCallback error
我尝试使用 PubNub 创建聊天应用程序。但是,如果尝试向 ArrayAdapter 添加消息文本,它就会崩溃。
在 successCallback 上它只调用带有消息的 AdaptAdd
这是它的代码:
public void AdaptAdd(String m) {
adp.add(m);
}
这是日志输出:
12-11 16:00:22.791 7206 7231 D PubNub [1,"Subscribe connected","14498279037104566"]
12-11 16:00:24.284 7206 7231 E AndroidRuntime FATAL EXCEPTION: Subscribe-Manager-136126964-3
12-11 16:00:24.284 7206 7231 E AndroidRuntime Process: com.redline.ichat, PID: 7206
12-11 16:00:24.284 7206 7231 E AndroidRuntime android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6556)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewRootImpl.focusableViewAvailable(ViewRootImpl.java:3034)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:761)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:761)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:761)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:761)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.View.setFlags(View.java:10555)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.View.setFocusableInTouchMode(View.java:7502)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.AdapterView.checkFocus(AdapterView.java:737)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:832)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:6179)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:301)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.ArrayAdapter.add(ArrayAdapter.java:197)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.redline.ichat.MainActivity.AdaptAdd(MainActivity.java:93)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.redline.ichat.MainActivity0000000.successCallback(MainActivity.java:52)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.Callback.successWrapperCallback(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.PubnubCore.invokeSubscribeCallback(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.PubnubCore.access00(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.PubnubCore.handleResponse(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.SubscribeWorker.process(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.Worker.run(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at java.lang.Thread.run(Thread.java:818)
12-11 16:00:24.655 7206 7232 E Surface getSlotFromBufferLocked: unknown buffer: 0xab43c300
您无法从后台线程访问视图。
您可以使用此代码来检查他们如何使用 notifyUser()
在主线程上执行操作
https://github.com/pubnub/java/blob/master/android/examples/PubnubExample/src/com/pubnub/examples/pubnubExample10/MainActivity.java
我尝试使用 PubNub 创建聊天应用程序。但是,如果尝试向 ArrayAdapter 添加消息文本,它就会崩溃。 在 successCallback 上它只调用带有消息的 AdaptAdd 这是它的代码:
public void AdaptAdd(String m) {
adp.add(m);
}
这是日志输出:
12-11 16:00:22.791 7206 7231 D PubNub [1,"Subscribe connected","14498279037104566"]
12-11 16:00:24.284 7206 7231 E AndroidRuntime FATAL EXCEPTION: Subscribe-Manager-136126964-3
12-11 16:00:24.284 7206 7231 E AndroidRuntime Process: com.redline.ichat, PID: 7206
12-11 16:00:24.284 7206 7231 E AndroidRuntime android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6556)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewRootImpl.focusableViewAvailable(ViewRootImpl.java:3034)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:761)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:761)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:761)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:761)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.View.setFlags(View.java:10555)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.view.View.setFocusableInTouchMode(View.java:7502)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.AdapterView.checkFocus(AdapterView.java:737)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:832)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:6179)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:301)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at android.widget.ArrayAdapter.add(ArrayAdapter.java:197)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.redline.ichat.MainActivity.AdaptAdd(MainActivity.java:93)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.redline.ichat.MainActivity0000000.successCallback(MainActivity.java:52)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.Callback.successWrapperCallback(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.PubnubCore.invokeSubscribeCallback(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.PubnubCore.access00(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.PubnubCore.handleResponse(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.SubscribeWorker.process(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at com.pubnub.api.Worker.run(Unknown Source)
12-11 16:00:24.284 7206 7231 E AndroidRuntime at java.lang.Thread.run(Thread.java:818)
12-11 16:00:24.655 7206 7232 E Surface getSlotFromBufferLocked: unknown buffer: 0xab43c300
您无法从后台线程访问视图。
您可以使用此代码来检查他们如何使用 notifyUser()
在主线程上执行操作
https://github.com/pubnub/java/blob/master/android/examples/PubnubExample/src/com/pubnub/examples/pubnubExample10/MainActivity.java