如何解决不幸的应用程序已停止

时间:2014-08-07 12:08:48

标签: listview android-activity android-listview runtime-error listviewitem

每次点击3次或更多次,应用程序都会遇到错误"不幸的应用程序已经停止"我猜是因为我不得不替换listview但是我不明白错误的位置,是有人可以帮助我

我的ItemListBaseAdapter

public class ItemListBaseAdapter extends BaseAdapter {
    private static ArrayList<ItemDetails> itemDetailsrrayList;

    private Integer[] imgid = {
            R.drawable.gesek1,
            R.drawable.goyang1,
            R.drawable.petik1,
            R.drawable.pukul1,
            R.drawable.tiup1,
            R.drawable.angklung1,
            R.drawable.bonang1,
            R.drawable.calung1,
            R.drawable.gong1,
            R.drawable.jengglong1,
            R.drawable.karinding1,
            R.drawable.kecapi1,
            R.drawable.kendang1,
            R.drawable.rebab1,
            R.drawable.saron1,
            R.drawable.suling1,
            R.drawable.tarawangsa1,
            };

    private LayoutInflater l_Inflater;

    public ItemListBaseAdapter(Context context, ArrayList<ItemDetails> results) {
        itemDetailsrrayList = results;
        l_Inflater = LayoutInflater.from(context);
    }

    public int getCount() {
        return itemDetailsrrayList.size();
    }

    public Object getItem(int position) {
        return itemDetailsrrayList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = l_Inflater.inflate(R.layout.item, null);
            holder = new ViewHolder();
            holder.txt_itemName = (TextView) convertView.findViewById(R.id.item_nama);
            holder.txt_itemDescription = (TextView) convertView.findViewById(R.id.item_keterangan);
            holder.itemImage = (ImageView) convertView.findViewById(R.id.item_icon);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.txt_itemName.setText(itemDetailsrrayList.get(position).getName());
        holder.txt_itemDescription.setText(itemDetailsrrayList.get(position).getItemDescription());
        holder.itemImage.setImageResource(imgid[itemDetailsrrayList.get(position).getImageNumber() - 1]);
//      imageLoader.DisplayImage("http://192.168.1.28:8082/ANDROID/images/BEVE.jpeg", holder.itemImage);

        return convertView;
    }

    static class ViewHolder {
        TextView txt_itemName;
        TextView txt_itemDescription;
        TextView txt_itemPrice;
        ImageView itemImage;
    }
}

我的LogCat

08-07 07:13:46.605: E/AndroidRuntime(894): FATAL EXCEPTION: main
08-07 07:13:46.605: E/AndroidRuntime(894): Process: com.example.alatmusik, PID: 894
08-07 07:13:46.605: E/AndroidRuntime(894): 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. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131034188, class android.widget.ListView) with Adapter(class com.example.alatmusik.ItemListBaseAdapter)]
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.widget.ListView.layoutChildren(ListView.java:1555)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.widget.AbsListView.onTouchUp(AbsListView.java:3617)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.widget.AbsListView.onTouchEvent(AbsListView.java:3429)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.View.dispatchTouchEvent(View.java:7706)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
08-07 07:13:46.605: E/AndroidRuntime(894):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
08-07 07:13:46.605: E/AndroidRuntime(894):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
08-07 07:13:46.605: E/AndroidRuntime(894):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.View.dispatchPointerEvent(View.java:7886)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3954)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3833)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5602)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5582)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5553)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5682)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.os.MessageQueue.nativePollOnce(Native Method)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.os.MessageQueue.next(MessageQueue.java:138)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.os.Looper.loop(Looper.java:123)
08-07 07:13:46.605: E/AndroidRuntime(894):  at android.app.ActivityThread.main(ActivityThread.java:5017)
08-07 07:13:46.605: E/AndroidRuntime(894):  at java.lang.reflect.Method.invokeNative(Native Method)
08-07 07:13:46.605: E/AndroidRuntime(894):  at java.lang.reflect.Method.invoke(Method.java:515)
08-07 07:13:46.605: E/AndroidRuntime(894):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-07 07:13:46.605: E/AndroidRuntime(894):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-07 07:13:46.605: E/AndroidRuntime(894):  at dalvik.system.NativeStart.main(Native Method)

请帮助我!

1 个答案:

答案 0 :(得分:0)

日志的第三行非常具有描述性。