2

我正在尝试做列表视图。我的应用程序在第一次打开时工作,但在返回主菜单后它不再工作并且在模拟器上给出错误“不幸的是应用程序已停止”。

这是我的主要内容。

public class ListMyJob extends Activity {
        ItemListBaseAdapter adapter;               //////after answers ı added.
        public void onBackPressed() {             //////after answers ı added.
                                                 //////after answers ı added.
            adapter.notifyDataSetChanged();      //////after answers ı added.

    }                                           //////after answers ı added.
    ArrayList<ItemDetails> jobs = new ArrayList<ItemDetails>();{   /////////////some list data /////////////////////}

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ArrayList<ItemDetails> image_details = jobs;

        final ListView lv1 = (ListView) findViewById(R.id.listV_main);
        lv1.setAdapter(new ItemListBaseAdapter(this, image_details));
        lv1.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
                Object o = lv1.getItemAtPosition(position);
                ItemDetails obj_itemDetails = (ItemDetails)o;
                Toast.makeText(ListMyJob.this, "You have chosen : " + " " + obj_itemDetails.getName(), Toast.LENGTH_LONG).show();
                Intent intObj = new Intent(ListMyJob.this,ListMyExercises.class);  /////modified

                intObj.putExtra("description",obj_itemDetails.getItemDescription());
                intObj.putExtra("name",obj_itemDetails.getName());
                intObj.putExtra("imagenumber",obj_itemDetails.getImageNumber());
                intObj.putExtra("videonumber", obj_itemDetails.getVideoNumber());

                ItemDetailsWrapper wrapper = new ItemDetailsWrapper(obj_itemDetails.getChild());
                intObj.putExtra("exerciselist", wrapper); // i.putExtra("obj", new ItemDetailsWrapper(list));

                startActivity(intObj);
            }  
        });
    }
}

我在 logcat 上收到这些错误。

04-24 09:31:44.596: E/InputEventReceiver(2170): Exception dispatching input event.
04-24 09:31:44.596: E/MessageQueue-JNI(2170): Exception in MessageQueue callback: handleReceiveCallback
04-24 09:31:44.676: E/MessageQueue-JNI(2170): 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(2131099660, class android.widget.ListView) with Adapter(class com.jsupport.HealthyMe.ItemListBaseAdapter)]
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.widget.ListView.layoutChildren(ListView.java:1544)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.widget.AbsListView.onTouchEvent(AbsListView.java:3403)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.View.dispatchTouchEvent(View.java:7246)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.View.dispatchPointerEvent(View.java:7426)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.os.MessageQueue.nativePollOnce(Native Method)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.os.MessageQueue.next(MessageQueue.java:125)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.os.Looper.loop(Looper.java:124)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at android.app.ActivityThread.main(ActivityThread.java:5041)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at java.lang.reflect.Method.invokeNative(Native Method)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at java.lang.reflect.Method.invoke(Method.java:511)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-24 09:31:44.676: E/MessageQueue-JNI(2170):   at dalvik.system.NativeStart.main(Native Method)
04-24 09:31:44.676: D/AndroidRuntime(2170): Shutting down VM
04-24 09:31:44.676: W/dalvikvm(2170): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-24 09:31:44.716: E/AndroidRuntime(2170): FATAL EXCEPTION: main
04-24 09:31:44.716: E/AndroidRuntime(2170): 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(2131099660, class android.widget.ListView) with Adapter(class com.jsupport.HealthyMe.ItemListBaseAdapter)]
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.widget.ListView.layoutChildren(ListView.java:1544)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.widget.AbsListView.onTouchEvent(AbsListView.java:3403)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.View.dispatchTouchEvent(View.java:7246)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.View.dispatchPointerEvent(View.java:7426)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.os.MessageQueue.nativePollOnce(Native Method)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.os.MessageQueue.next(MessageQueue.java:125)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.os.Looper.loop(Looper.java:124)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at java.lang.reflect.Method.invokeNative(Native Method)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at java.lang.reflect.Method.invoke(Method.java:511)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-24 09:31:44.716: E/AndroidRuntime(2170):     at dalvik.system.NativeStart.main(Native Method)
04-24 09:36:44.811: I/Process(2170): Sending signal. PID: 2170 SIG: 9
4

1 回答 1

2

利用

onBakcPressed(){
  adapter.notifydatasetchanged();
}
于 2013-04-24T10:16:37.563 回答