ListView + ViewPager No resource found on onResume event

I have a frustrating problem in my application:

  • I have a Fragment that contains one ListView .
  • Each row of the ListView loads the ViewPager and ViewPagerCustomIndicator objects from an XML file.
  • For each ViewPager loaded , I set the Id to viewHolder.viewPager.setId (Utils.generateViewId ()); ; I find this advice here .
  • The ListView data is loaded into onResume Fragment .

In the beginning, everything works fine . On boot, the second application crashes with this log:

08-26 15: 39: 05.441: E / AndroidRuntime (31633): Process: com.playyoo.android.sportyes, PID: 31633 08-26 15: 39: 05.441: E / AndroidRuntime (31 633): android.content. res.Resources $ NotFoundException: Unable to find resource ID # 0x1 08-26 15: 39: 05.441:E / AndroidRuntime (31633): at android.content.res.Resources.getResourceName (Resources.java:1773) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4.app.FragmentManagerImpl .moveToState (FragmentManager.java:934) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1121) 08-26 15: 39 : 05.441: E / AndroidRuntime (31633): at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1103) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support. v4.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManager.java:1901) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4.app.Fragment.performActivityCreated (Fragment.java:1518) 08 -26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:962) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1121) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4.app.BackStackRecord.popFromBackStack (BackStackRecord.java:764) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4 .app.FragmentManagerImpl.popBackStackState (FragmentManager.java:1533) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4.app.FragmentManagerImpl $ 2.run (FragmentManager.java:489) 08 -26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:1484) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.support.v4.app.FragmentManagerImpl $ 1.run (FragmentManager.java:450) 08-26 15: 39: 05.441:E / AndroidRuntime (31633): at android.os.Handler.handleCallback (Handler.java:733) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.os.Handler.dispatchMessage (Handler.java : 95) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.os.Looper.loop (Looper.java:136) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.app.ActivityThread.main (ActivityThread.java:5001) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at java.lang.reflect.Method.invoke (native method) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:785) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at com .android.internal.os.ZygoteInit.main (ZygoteInit.java:601)at android.os.Handler.dispatchMessage (Handler.java:95) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.os.Looper.loop (Looper.java:136) 08-26 15 : 39: 05.441: E / AndroidRuntime (31633): at android.app.ActivityThread.main (ActivityThread.java:5001) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at java.lang.reflect. Method.invoke (native method) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:785) 08-26 15:39 : 05.441: E / AndroidRuntime (31633): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:601)at android.os.Handler.dispatchMessage (Handler.java:95) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at android.os.Looper.loop (Looper.java:136) 08-26 15 : 39: 05.441: E / AndroidRuntime (31633): at android.app.ActivityThread.main (ActivityThread.java:5001) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at java.lang.reflect. Method.invoke (native method) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:785) 08-26 15:39 : 05.441: E / AndroidRuntime (31633): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:601)5001) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at java.lang.reflect.Method.invoke (native method) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at com .android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:785) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at com.android.internal.os.ZygoteInit.main (ZygoteInit. java: 601)5001) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at java.lang.reflect.Method.invoke (native method) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at com .android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:785) 08-26 15: 39: 05.441: E / AndroidRuntime (31633): at com.android.internal.os.ZygoteInit.main (ZygoteInit. java: 601)

It's good the error is obvious , but I can't seem to find a solution to fix it. Without the ViewPager, the app works fine.

This is my adapter (in this example I am not using the android cell recycling mechanism):

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        XmlEvento e = (XmlEvento) getItem(position);

        final ViewHolder viewHolder = new ViewHolder();

        View view = _mInflater.inflate(_graphicResource, null);
        viewHolder.viewPager = (ViewPager) view
                .findViewById(R.id.live_view_pager);
        viewHolder.viewPagerIndicator = (ViewPagerIndicator) view
                .findViewById(R.id.live_view_pager_indicator);
        // viewHolder.viewPager.setId(position + 1);
        viewHolder.viewPager.setId(Utils.generateViewId());

        view.setTag(viewHolder);

        final List<Fragment> fragments = new Vector<Fragment>();

        for (int i = 0; i < scommesse.size(); i++) {

            XmlScommesse scommmessa = scommesse.get(i);

            Fragment fr = Live_Level_1_BetRow_Fragment.newInstance(e,
                    scommmessa);
            fragments.add(fr);
        }

            final String eId = getEventId(e);
            final Live_Bet_Level_1_Adapter mPagerAdapter = new Live_Bet_Level_1_Adapter(
                    _fragmentManager, fragments, _iBet);

            viewHolder.viewPager.setAdapter(mPagerAdapter);
            viewHolder.viewPager.setCurrentItem(_viewPagerStoredPosition
                    .get(eId));

                // Bind the circle indicator to the adapter.
                viewHolder.viewPagerIndicator
                        .setViewPager(viewHolder.viewPager);
                viewHolder.viewPagerIndicator
                        .setOnPageChangeListener(new OnPageChangeListener() {

                            @Override
                            public void onPageSelected(int p) {

                                Live_Level_1_BetRow_Fragment fr = (Live_Level_1_BetRow_Fragment) fragments
                                        .get(p);
                                fr.setAdapter(mPagerAdapter);
                            }

                            @Override
                            public void onPageScrollStateChanged(int position) {
                                // TODO Auto-generated method stub
                            }

                            @Override
                            public void onPageScrolled(int position,
                                    float positionOffset,
                                    int positionOffsetPixels) {
                                // TODO Auto-generated method stub
                            }
                        });

      

Live_Level_1_BetRow_Fragment.newInstance (e, rate); si is a simple snippet that contains:

view = inflater.inflate (R.layout.MY_ROW_LAYOUT, container, false);

Thank you for your suggestions.

+3


source to share





All Articles