GithubHelp home page GithubHelp logo

java.lang.NullPointerException: Attempt to invoke virtual method 'int com.solaris.want2know.infinitecyclerviewpager.InfiniteCyclePagerAdapter.getVirtualPosition(int)' on a null object reference about infinitecycleviewpager HOT 7 CLOSED

devlight avatar devlight commented on May 7, 2024
java.lang.NullPointerException: Attempt to invoke virtual method 'int com.solaris.want2know.infinitecyclerviewpager.InfiniteCyclePagerAdapter.getVirtualPosition(int)' on a null object reference

from infinitecycleviewpager.

Comments (7)

droid-wise avatar droid-wise commented on May 7, 2024

Here is the whole activity code, and i would really appreciate some help here:

`public class HomeActivity extends AppCompatActivity implements OnLikeListener {

private List<Post> mPosts = new ArrayList<>();
private SimpleFacebook mSimpleFacebook;
private VerticalInfiniteCycleViewPager infiniteCycleViewPager;

private Permission[] mPermissions = new Permission[]{
        Permission.USER_PHOTOS,
        Permission.PUBLISH_ACTION,
        Permission.USER_LIKES,
};

private DialogLoadingScreen progressDialog;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Making notification bar transparent
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
    setContentView(R.layout.activity_home);
    progressDialog  = DialogLoadingScreen.newInstance();
    mSimpleFacebook = SimpleFacebook.getInstance(this);
    initViews();
    initLikeButton();
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            showProgressDialog();
        }
    }, 1000);
    mSimpleFacebook.requestNewPermissions(mPermissions, onNewPermissionListener);

    Util.changeStatusBarColor(this);
}

private void configureInfinitiveCycleViewPager() {
    infiniteCycleViewPager =
            (VerticalInfiniteCycleViewPager) findViewById(R.id.view_pager);
    VerticalPagerAdapter adapter = new VerticalPagerAdapter(getSupportFragmentManager(), mPosts);
    infiniteCycleViewPager.setAdapter(adapter);
}

private void initViews() {
    ImageView imageView   = (ImageView) findViewById(R.id.iv_background);
    Glide.with(HomeActivity.this)
            .load(R.drawable.background)
            .crossFade()
            .centerCrop()
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(imageView);

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            Blurry.with(HomeActivity.this)
                    .radius(25)
                    .sampling(1)
                    .async()
                    .capture(findViewById(R.id.iv_background))
                    .into((ImageView) findViewById(R.id.iv_background));
        }
    }, 500);
}

private void initLikeButton() {
    LikeButton likeButton = (LikeButton) findViewById(R.id.thumb_button);
    likeButton.setOnLikeListener(this);
}

@Override
protected void onResume() {
    super.onResume();
    mSimpleFacebook = SimpleFacebook.getInstance(this);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    mSimpleFacebook.onActivityResult(requestCode, resultCode, data);
    super.onActivityResult(requestCode, resultCode, data);
}

/***************************
 * Facebook Methods
 *****************************/

OnNewPermissionsListener onNewPermissionListener = new OnNewPermissionsListener() {
    @Override
    public void onSuccess(String accessToken,
                          List<Permission> acceptedPermissions,
                          List<Permission> declinedPermissions) {
        Log.d("Access Token: ", accessToken);
        Bundle params = new Bundle();
        params.putString("fields",
                "picture, url, source, created_time");
        params.putString("limit", "1000");

        String entityId = "957672727688311";

        mSimpleFacebook.get(entityId, "photos/uploaded", params, onActionListener);
    }

    @Override
    public void onCancel() {

    }

    @Override
    public void onException(Throwable throwable) {

    }

    @Override
    public void onFail(String reason) {

    }
};

OnActionListener<List<Photo>> onActionListener = new OnActionListener<List<Photo>>() {
    @Override
    public void onComplete(List<Photo> photos) {
        configureInfinitiveCycleViewPager();

        hideProgressDialog();
        for (Photo photo : photos) {
            Post post = new Post();
            post.setPhotoId(photo.getId());
            post.setSource(photo.getSource());
            post.setCreatedTime(photo.getCreatedTime());
            mPosts.add(post);
        }

        sortList(mPosts);
        infiniteCycleViewPager.notifyDataSetChanged();
    }
};

private void sortList(List<Post> posts) {
    Collections.sort(posts, new Comparator<Post>() {
        @Override
        public int compare(Post o1, Post o2) {
            if (o1.getCreatedTime() == null || o2.getCreatedTime() == null)
                return 0;
            return o2.getCreatedTime().compareTo(o1.getCreatedTime());
        }
    });
}

@Override
public void onBackPressed() {
    super.onBackPressed();
    this.finish();
}

private void showProgressDialog() {
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(progressDialog, "loading");
    transaction.commitAllowingStateLoss();

    progressDialog.setCancelable(false);
}

private void hideProgressDialog() {
    if (progressDialog.isVisible()) {
        progressDialog.dismiss();
    }
}

public SimpleFacebook getSimpleFacebook() {
    return mSimpleFacebook;
}

public VerticalInfiniteCycleViewPager getInfiniteCycleViewPager() {
    return infiniteCycleViewPager;
}

@Override
public void liked(LikeButton likeButton) {
    int position       = infiniteCycleViewPager.getRealItem();
    final Post post    = mPosts.get(position);

    Like like    = new Like.Builder().build();
    mSimpleFacebook.publish(post.getPhotoId(), like, new OnPublishListener() {
        @Override
        public void onComplete(String response) {
            TastyToast.makeText(HomeActivity.this, response, TastyToast.LENGTH_LONG,
                    TastyToast.DEFAULT);
        }

        @Override
        public void onException(Throwable throwable) {
            super.onException(throwable);
        }

        @Override
        public void onFail(String reason) {
            super.onFail(reason);
        }

        @Override
        public void onThinking() {
            super.onThinking();
        }
    });
}

@Override
public void unLiked(LikeButton likeButton) {

}

}
`

from infinitecycleviewpager.

GIGAMOLE avatar GIGAMOLE commented on May 7, 2024

Hello. Thanks for this issue.
I'll try to fix this soon.

from infinitecycleviewpager.

droid-wise avatar droid-wise commented on May 7, 2024

Thank you for responding here so fast. Your library is awesome. Just if this bug can be fixed, it would be great, i really need that feature, getting position of selected item in ViewPager.

from infinitecycleviewpager.

GIGAMOLE avatar GIGAMOLE commented on May 7, 2024

This is very interesting, because method doesnt invoke npe. Try to fix.

from infinitecycleviewpager.

droid-wise avatar droid-wise commented on May 7, 2024

Well i have tried, but i always got null object reference. Can you look at the code and see if you can find any mistake i have made?

from infinitecycleviewpager.

hassanimsuya79 avatar hassanimsuya79 commented on May 7, 2024

from infinitecycleviewpager.

hassanimsuya79 avatar hassanimsuya79 commented on May 7, 2024

from infinitecycleviewpager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.