【问题标题】:I get crash my listView. Exception dispatching input event我的 listView 崩溃了。异常调度输入事件
【发布时间】:2016-08-11 17:55:57
【问题描述】:

我有一个 ListView(图像 + 文本),我从 Internet 加载数据。 我扩展了我的 ListView 批处理。如果我在不加载图像的情况下关闭互联网并触摸视图(来自 ListView),我会收到错误消息。

这是我的适配器代码:

public class AdapterListGroups extends BaseAdapter {

    private List<ItemMusicGroup> listItemsMusicGroup;
    private LayoutInflater layoutInflater;
    private LoaderData loaderData;
    final private int heightForLoad;

    public AdapterListGroups(Context context, List<ItemMusicGroup> listItemsMusicGroup, LoaderData loaderData) {
        this.listItemsMusicGroup = listItemsMusicGroup;
        this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.loaderData = loaderData;
        this.heightForLoad = context.getResources().getInteger(R.integer.sizeOfListView) / 2;//Параметр который определяет когда нужно подгружать данные в список
    }

    @Override
    public int getCount() {
        if ( this.listItemsMusicGroup.isEmpty() ) loaderData.extentionListItemsMusicGroup(listItemsMusicGroup, 0);//Если список пустой, подгружаем первые данне
        return this.listItemsMusicGroup.size();
    }

    @Override
    public Object getItem(int position) {
        Log.d("INFO", "getItem" + position);
        //При прокрутке смотрим нужно ли увечичвать список
        if (checkNeedExtention(position))
            loaderData.extentionListItemsMusicGroup(listItemsMusicGroup, position);
        return this.listItemsMusicGroup.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if ( view == null ) {
            view = layoutInflater.inflate(R.layout.list_item, parent, false);
        }
        ItemMusicGroup currentItemMusicGroup = getItemMusicGroup(position);
        setTextContentItem(view, currentItemMusicGroup);
        setImageContentItem(view, currentItemMusicGroup);
        return view;
    }

    //Заполняем миниатюры для картинок
    private void setImageContentItem(View view, ItemMusicGroup currentItemMusicGroup)
    {
        if ( currentItemMusicGroup.getLinkSmallImage() != null) {
            NetworkImageView networkImageView = (NetworkImageView) view.findViewById(R.id.item_networkImageView_icon);
            networkImageView.setImageUrl(currentItemMusicGroup.getLinkSmallImage(), loaderData.getImageLoader());
        }
    }
    //Заполняем данные в TextView
    private void setTextContentItem(View view, ItemMusicGroup currentItemMusicGroup)
    {
        try {

            setTextForTextView(view, R.id.item_textView_nameGroup, currentItemMusicGroup.getName());
            setTextForTextView(view, R.id.list_item_textView_countAlbum, currentItemMusicGroup.getAlbumsString());
            setTextForTextView(view, R.id.list_item_textView_countSing, currentItemMusicGroup.getTracksString());
            setTextForTextView(view, R.id.list_item_TextView_genres, currentItemMusicGroup.getGenresString());

        } catch (Exception e) {
            Log.d(getStringResource(R.string.log_tag_error, view), this.getClass().getSimpleName() + view.toString());
        }

    }

    private void setTextForTextView( View view, int resIdView, String textContent) {
        TextView nameGroup = (TextView) view.findViewById(resIdView);
        if ( textContent == null) {
            textContent = getStringResource(R.string.defaultValueParametr, view);
        }
        nameGroup.setText(textContent);
    }

    private String getStringResource(int resourseId, View view)
    {
        return view.getContext().getResources().getString(resourseId);
    }

    public ItemMusicGroup getItemMusicGroup(int position) {
        return (ItemMusicGroup) getItem(position);
    }

    private boolean checkNeedExtention(int position)
    {
        if (position >= listItemsMusicGroup.size() - heightForLoad && position < loaderData.getSizeJSONArray())
        {
            return true;
        } else return false;
    }
}

这是我的 Logcat。

E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
com.main.hubluzar.musicapp E/MessageQueue-JNI: 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(2131492964, class android.widget.ListView) with Adapter(class com.main.hubluzar.musicapp.adapter.AdapterListGroups)]
        at android.widget.ListView.layoutChildren(ListView.java:1555)
        at android.widget.AbsListView.onTouchUp(AbsListView.java:3624)
        at android.widget.AbsListView.onTouchEvent(AbsListView.java:3436)
        at android.view.View.dispatchTouchEvent(View.java:7706)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
        at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
        at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
        at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
        at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
        at android.view.View.dispatchPointerEvent(View.java:7886)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5532)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5512)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5483)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5612)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:138)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)

com.main.hubluzar.musicapp W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb3adfba8)
        Process: com.main.hubluzar.musicapp, PID: 2587
        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(2131492964, class android.widget.ListView) with Adapter(class com.main.hubluzar.musicapp.adapter.AdapterListGroups)]
        at android.widget.ListView.layoutChildren(ListView.java:1555)
        at android.widget.AbsListView.onTouchUp(AbsListView.java:3624)
        at android.widget.AbsListView.onTouchEvent(AbsListView.java:3436)
        at android.view.View.dispatchTouchEvent(View.java:7706)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
        at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
        at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
        at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
        at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
        at android.view.View.dispatchPointerEvent(View.java:7886)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5532)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5512)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5483)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5612)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:138)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Na

【问题讨论】:

  • 请贴出使用这个listview apdater的活动代码

标签: android listview android-volley


【解决方案1】:

我找到了我的问题的答案。 也许它对任何人都有用。 当我扩展我的listItemsMusicGroup 时,我必须调用notifyDataSetChanged() 以更新ListView

public Object getItem(int position) {

    //When scrolling, let's see if it is necessary to improve the list

    if (checkNeedExtention(position)) {
        loaderData.extentionListItemsMusicGroup(listItemsMusicGroup, position);
        notifyDataSetChanged();
    }
    return this.listItemsMusicGroup.get(position);
}

【讨论】:

    猜你喜欢
    • 2014-09-05
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-15
    • 1970-01-01
    相关资源
    最近更新 更多