2016-04-19 23 views
2

私はListView(画像+テキスト)を持っていて、インターネットからデータをロードします。 ListViewバッチを拡張します。インターネットをオフにし、画像をロードせずに(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 
+1

このlistview apdaterを使用しているアクティビティコードを投稿してください –

答えて

0

私の質問に答えが見つかりました。 多分それは誰にも役立つでしょう。 私はlistItemsMusicGroupを拡張するとき、ListViewの更新のためにnotifyDataSetChanged()を呼び出す必要があります。

public Object getItem(int position) { 
    //При прокрутке смотрим нужно ли увечичвать список 
    if (checkNeedExtention(position)) { 
     loaderData.extentionListItemsMusicGroup(listItemsMusicGroup, position); 
     notifyDataSetChanged(); 
    } 
    return this.listItemsMusicGroup.get(position); 
} 
関連する問題