应用程序停止改变页 [英] Application stops on changing page
问题描述
我在一个应用程序在那里我得到来自服务器的响应不断,但是当我改变页面或移动到其他屏幕上的应用程序获得stop.I正在接收来自服务器的响应,但它不是在列表视图更新。<工作/ p>
我用 onResume
和的onPause
方法也不过还是我收到错误。
code;
保护类GetTask扩展的AsyncTask&LT;太虚,太虚,整数GT; { @覆盖
保护整数doInBackground(虚空...... PARAMS){
// TODO自动生成方法存根
尝试{
CallReceiveMsgAPIService();
}赶上(例外五){
}
返回0;
} @覆盖
保护无效onPostExecute(整数结果){
// TODO自动生成方法存根
super.onPostExecute(结果);
尝试{
如果(发起!= 1){
mMessageHandle.sendEmptyMessage(0);
新GetTask()执行(); }
}其他{
mLiveChatList.setAdapter(适配器);
adapter.notifyDataSetChanged();
mLiveChatList.requestLayout();
警报();
}
}赶上(例外五){
} }
}
错误:
05-10 14:14:01.213:E / AndroidRuntime(277):致命异常:主要
05-10 14:14:01.213:E / AndroidRuntime(277):java.lang.IllegalStateException:适配器的内容发生了变化,但ListView控件没有收到通知。确保您的适配器的内容不是从后台线程修改,但只能从UI线程。 [中的ListView(2131361857,类android.widget.ListView)与适配器(类融为一体$ ChatListAdapter)
05-10 14:14:01.213:E / AndroidRuntime(277):在android.widget.ListView.layoutChildren(ListView.java:1492)
05-10 14:14:01.213:E / AndroidRuntime(277):在android.widget.AbsListView.onTouchModeChanged(AbsListView.java:1960)
05-10 14:14:01.213:E / AndroidRuntime(277):在android.view.ViewTreeObserver.dispatchOnTouchModeChanged(ViewTreeObserver.java:591)
05-10 14:14:01.213:E / AndroidRuntime(277):在android.view.ViewRoot.ensureTouchModeLocally(ViewRoot.java:2021)
05-10 14:14:01.213:E / AndroidRuntime(277):在android.view.ViewRoot.ensureTouchMode(ViewRoot.java:2005)
05-10 14:14:01.213:E / AndroidRuntime(277):在android.view.ViewRoot.handleMessage(ViewRoot.java:1774)
05-10 14:14:01.213:E / AndroidRuntime(277):在android.os.Handler.dispatchMessage(Handler.java:99)
05-10 14:14:01.213:E / AndroidRuntime(277):在android.os.Looper.loop(Looper.java:123)
05-10 14:14:01.213:E / AndroidRuntime(277):在android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 14:14:01.213:E / AndroidRuntime(277):在java.lang.reflect.Method.invokeNative(本机方法)
05-10 14:14:01.213:E / AndroidRuntime(277):在java.lang.reflect.Method.invoke(Method.java:521)
05-10 14:14:01.213:E / AndroidRuntime(277):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 14:14:01.213:E / AndroidRuntime(277):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 14:14:01.213:E / AndroidRuntime(277):在dalvik.system.NativeStart.main(本机方法)
可能有人让我离开这个.. @谢谢
呼叫 adapter.notifyDataSetChanged();
后出现在列表更改通知的ListView
该列表中的内容发生了变化。这必将解决这个错误。
保护类GetTask扩展的AsyncTask&LT;太虚,太虚,整数GT; {
公共接口TaskListener
{
公共无效updateResult(对象结果);
}
私人TaskListener侦听器;
@覆盖
保护整数doInBackground(虚空...... PARAMS){
// TODO自动生成方法存根
尝试{
CallReceiveMsgAPIService();
}赶上(例外五){
}
返回0;
} @覆盖
保护无效onPostExecute(整数结果){
// TODO自动生成方法存根
super.onPostExecute(结果);
尝试{
如果(发起!= 1){
mMessageHandle.sendEmptyMessage(0);
新GetTask()执行(); }
}其他{ listener.updateResult(结果);
//mLiveChatList.setAdapter(adapter);
//adapter.notifyDataSetChanged();
// mLiveChatList.requestLayout();
//警报();
}
}赶上(例外五){
} }
}
在活动实现这个接口TaskListener并在updateresult方法做code评论说。
I am working in one application where i am getting continuous response from server but when i change the page or moved to the other screen the application gets stop.I am receiving the response from server but it is not updating in listview.
I have used onResume
and onPause
method also but still i am receiving the error.
code;
protected class GetTask extends AsyncTask<Void, Void, Integer> {
@Override
protected Integer doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
CallReceiveMsgAPIService();
} catch (Exception e) {
}
return 0;
}
@Override
protected void onPostExecute(Integer result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
try {
if (initiate != 1) {
mMessageHandle.sendEmptyMessage(0);
new GetTask().execute();
}
} else {
mLiveChatList.setAdapter(adapter);
adapter.notifyDataSetChanged();
mLiveChatList.requestLayout();
alert();
}
} catch (Exception e) {
}
}
}
error:
05-10 14:14:01.213: E/AndroidRuntime(277): FATAL EXCEPTION: main
05-10 14:14:01.213: E/AndroidRuntime(277): 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(2131361857, class android.widget.ListView) with Adapter(class com.$ChatListAdapter)]
05-10 14:14:01.213: E/AndroidRuntime(277): at android.widget.ListView.layoutChildren(ListView.java:1492)
05-10 14:14:01.213: E/AndroidRuntime(277): at android.widget.AbsListView.onTouchModeChanged(AbsListView.java:1960)
05-10 14:14:01.213: E/AndroidRuntime(277): at android.view.ViewTreeObserver.dispatchOnTouchModeChanged(ViewTreeObserver.java:591)
05-10 14:14:01.213: E/AndroidRuntime(277): at android.view.ViewRoot.ensureTouchModeLocally(ViewRoot.java:2021)
05-10 14:14:01.213: E/AndroidRuntime(277): at android.view.ViewRoot.ensureTouchMode(ViewRoot.java:2005)
05-10 14:14:01.213: E/AndroidRuntime(277): at android.view.ViewRoot.handleMessage(ViewRoot.java:1774)
05-10 14:14:01.213: E/AndroidRuntime(277): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 14:14:01.213: E/AndroidRuntime(277): at android.os.Looper.loop(Looper.java:123)
05-10 14:14:01.213: E/AndroidRuntime(277): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 14:14:01.213: E/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 14:14:01.213: E/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
05-10 14:14:01.213: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 14:14:01.213: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 14:14:01.213: E/AndroidRuntime(277): at dalvik.system.NativeStart.main(Native Method)
could anybody get me out of this ..@Thanks
Call adapter.notifyDataSetChanged();
after there is a change in the list to notify the listView
that the contents of list have changed. This will surely solve this error.
protected class GetTask extends AsyncTask<Void, Void, Integer> {
public interface TaskListener
{
public void updateResult(Object result);
}
private TaskListener listener;
@Override
protected Integer doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
CallReceiveMsgAPIService();
} catch (Exception e) {
}
return 0;
}
@Override
protected void onPostExecute(Integer result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
try {
if (initiate != 1) {
mMessageHandle.sendEmptyMessage(0);
new GetTask().execute();
}
} else {
listener.updateResult(result);
//mLiveChatList.setAdapter(adapter);
//adapter.notifyDataSetChanged();
// mLiveChatList.requestLayout();
// alert();
}
} catch (Exception e) {
}
}
}
In activity implement this interface TaskListener and in the updateresult method do the code commented.
这篇关于应用程序停止改变页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!