Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException #82

Open
ankitdubey021 opened this issue May 4, 2019 · 6 comments
Open

NullPointerException #82

ankitdubey021 opened this issue May 4, 2019 · 6 comments

Comments

@ankitdubey021
Copy link

Can anyone suggest me, why i'm getting this exception?

java.lang.NullPointerException: Attempt to invoke interface method 'void androidx.viewpager.widget.ViewPager$OnPageChangeListener.onPageScrolled(int, float, int)' on a null object reference
at com.veinhorn.scrollgalleryview.ScrollGalleryView$5.onPageScrolled(

@VEINHORN
Copy link
Owner

VEINHORN commented May 4, 2019

@ankitdubey021 Hi! Which version of library do you use?

@ankitdubey021
Copy link
Author

ankitdubey021 commented May 4, 2019

@VEINHORN thank you for response.
i'm using below two libraries
implementation 'com.veinhorn.scrollgalleryview:library:1.2.8'
implementation 'com.veinhorn.scrollgalleryview:picasso-loader:1.2.8'

And here is my same code, you've mentioned.

galleryView = ScrollGalleryView
.from((ScrollGalleryView) findViewById(R.id.scroll_gallery_view))
.settings(
GallerySettings
.from(getSupportFragmentManager())
.thumbnailSize(100)
.enableZoom(true)
.build()
)
.add(image("http://pirate-islands.com/wp-content/uploads/2018/07/07_Dom-Fernando-II_01-636x310.jpg"))
.add(image("http://povodu.ru/wp-content/uploads/2016/04/pochemu-korabl-derzitsa-na-vode.jpg"))
//.add(video("http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4", R.mipmap.default_video))
.build();

@tannu031
Copy link

hey @VEINHORN i am also getting the same error kindly help

@rajeshlakkakula-dev
Copy link

hey @VEINHORN I'm also getting same error . Kindly Help

@mojtaba-yekta
Copy link

I also getting same error so I just defined empty listener like below and problem solved:


//after create new list instance I filled array list with some image and video url
List<String> imageList = new ArrayList<>();
List<String> videoList = new ArrayList<>();

//todo: fill lists with urls

GalleryBuilder gb = ScrollGalleryView
		.from(scroll_gallery_view)
		.settings(
				GallerySettings
						.from(getSupportFragmentManager())
						.thumbnailSize(100)
						.enableZoom(true)
						.build()
		)
		.onPageChangeListener(new ViewPager.OnPageChangeListener() {
			@Override
			public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

			}

			@Override
			public void onPageSelected(int position) {

			}

			@Override
			public void onPageScrollStateChanged(int state) {

			}
		});
for (String item : imageList) {
	gb = gb.add(image(item));
}
for (String item : videoList) {
	gb = gb.add(video(item,R.mipmap.default_video));
}
scroll_gallery_view = gb.build();

for complete fix, in ScrollGalleryView.java class @VEINHORN should change addOnPageChangeListener method to this:

public ScrollGalleryView addOnPageChangeListener(final ViewPager.OnPageChangeListener listener) {
        viewPager.clearOnPageChangeListeners();

        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
				if(listener!=null)
					listener.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }

            @Override public void onPageSelected(int position) {
                scroll(thumbnailsContainer.getChildAt(position));
				if(listener!=null)
					listener.onPageSelected(position);
            }

            @Override public void onPageScrollStateChanged(int state) {
				if(listener!=null)
					listener.onPageScrollStateChanged(state);
            }
        });

        return this;
    }

@LakshayDCoder
Copy link

Yeah @VEINHORN pls, fix this issue and thanks to @mojtaba-yekta his solution is working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants