question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Attempt to invoke virtual method 'int me.yokeyword.fragmentation.anim.FragmentAnimator.getEnter()' on a null object reference

See original GitHub issue

viewpage 使用FragmentStatePagerAdapter,点击position-1出现

java.lang.NullPointerException: Attempt to invoke virtual method 'int me.yokeyword.fragmentation.anim.FragmentAnimator.getEnter()' on a null object reference at me.yokeyword.fragmentation.helper.internal.AnimatorHelper.initEnterAnim(AnimatorHelper.java:63) at me.yokeyword.fragmentation.helper.internal.AnimatorHelper.notifyChanged(AnimatorHelper.java:29) at me.yokeyword.fragmentation.helper.internal.AnimatorHelper.<init>(AnimatorHelper.java:24) at me.yokeyword.fragmentation.SupportFragmentDelegate.onCreate(SupportFragmentDelegate.java:117) at xxx.BaseFragment.onCreate(BaseFragment.java:69) at xxx.ChannelFragment.onCreate(ChannelFragment.java:80) at android.support.v4.app.Fragment.performCreate(Fragment.java:2246) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1377) at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1187) at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:1070) at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:115) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2374) at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332) at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2209) at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:649) at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:167) at android.support.v4.view.ViewPager.populate(ViewPager.java:1238) at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:663) at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:625) at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:606) at android.support.design.widget.TabLayout$ViewPagerOnTabSelectedListener.onTabSelected(TabLayout.java:2170) at android.support.design.widget.TabLayout.dispatchTabSelected(TabLayout.java:1165) at android.support.design.widget.TabLayout.selectTab(TabLayout.java:1158) at android.support.design.widget.TabLayout.selectTab(TabLayout.java:1128) at android.support.design.widget.TabLayout$Tab.select(TabLayout.java:1427) at android.support.design.widget.TabLayout$TabView.performClick(TabLayout.java:1537) at android.view.View$PerformClick.run(View.java:23645) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6646) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
timmy008commented, Mar 30, 2018

问题找到了,我自己的代码问题,我起实现ISupportFragment这个接口,Fragment生命周期方法没有去重写,只重写了你这个接口里面的方法

0reactions
timmy008commented, Mar 30, 2018

` mPagerAdapter = new MyPagerAdapter(mActivity.getSupportFragmentManager()); viewPager.setAdapter(mPagerAdapter); tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); tabLayout.setupWithViewPager(viewPager);

    mWebApi.channels()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doOnSubscribe(() -> mStatusLayout.showLoading())
                    .subscribe(this::onSuccess, error -> mStatusLayout.showRetry(), () -> 
                    mStatusLayout.showContent()));

 private void setData(List<ChannelsInfo.ColumnListBean> columnList){
             mPagerAdapter.setNewData(columnList);
}

`

` public class MyPagerAdapter extends FragmentPagerAdapter {

private List<ChannelsInfo.ColumnListBean> mTitles = new ArrayList<>();

public MyPagerAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int position) {
    if (position == 0) {
        return HomeRecommendFragment.newInstance();
    } else {
        return ChannelFragment.getInstance(position);
    }
}

@Override
public CharSequence getPageTitle(int position) {
    return mTitles.get(position).getContent();
}

@Override
public int getCount() {
    return mTitles == null ? 0 : mTitles.size();
}


public void setNewData(List<ChannelsInfo.ColumnListBean> titleList) {
    mTitles.clear();
    mTitles = new ArrayList<>(titleList);
    notifyDataSetChanged();
}

} `

大致逻辑是这样的

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.NullPointerException:Attempt to invoke ... - GitHub
java.lang.NullPointerException:Attempt to invoke virtual method 'int me.yokeyword.fragmentation.anim.FragmentAnimator.getEnter()' on a null object reference.
Read more >
Attempt to invoke virtual method null object reference
You try to get the TextView via findViewById() from within ActivityMain.java, but the TextView is declared in fragment_deal.xlm.
Read more >
Attempt to invoke virtual method on a null object reference Fixed
java.lang.NullPointerException: Attempt to invoke virtual method on a null object reference Fixed Coding With Hammad ...
Read more >
Fixed Error android error attempt to invoke virtual method
Need Help or Code Support? Feel Free To Contact Us Here http://www.aaviskar.com/support.phpThis video is about Fixed Error android error ...
Read more >
Attempt to Invoke Virtual Method androidx.appcompat.app ...
Attempt to Invoke Virtual Method androidx.appcompat.app.ActionBar.hide() on a Null Object ReferenceHello Guys Welcome back, So in this video ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found