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

RuntimeException when building image viewer #83

Open
LouisPennachio opened this issue Apr 11, 2018 · 0 comments
Open

RuntimeException when building image viewer #83

LouisPennachio opened this issue Apr 11, 2018 · 0 comments

Comments

@LouisPennachio
Copy link

LouisPennachio commented Apr 11, 2018

I would like to instantiate the image viewer before actually showing it but I get this exception when using the "build()" method.

myActivity.runOnUiThread(new Runnable() {
    ImageViewer viewer = new ImageViewer.Builder(getContext(), originalUrls)
        .setStartPosition(0)
        .allowZooming(true)
        .build(); // Crash occurs here

    @Override
    public void run() {
        planImage.setOnClickListener(v -> viewer.show());
    }
});

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.(Handler.java:200)
at android.os.Handler.(Handler.java:114)
at android.view.GestureDetector$GestureHandler.(GestureDetector.java:290)
at android.view.GestureDetector.(GestureDetector.java:395)
at android.view.ScaleGestureDetector.setQuickScaleEnabled(ScaleGestureDetector.java:477)
at android.view.ScaleGestureDetector.(ScaleGestureDetector.java:227)
at android.view.ScaleGestureDetector.(ScaleGestureDetector.java:202)
at com.stfalcon.frescoimageviewer.ImageViewerView.init(ImageViewerView.java:143)
at com.stfalcon.frescoimageviewer.ImageViewerView.(ImageViewerView.java:65)
at com.stfalcon.frescoimageviewer.ImageViewer.createDialog(ImageViewer.java:72)
at com.stfalcon.frescoimageviewer.ImageViewer.(ImageViewer.java:53)
at com.stfalcon.frescoimageviewer.ImageViewer$Builder.build(ImageViewer.java:426)

I don't have any issue if I do this instead :

myActivity.runOnUiThread(new Runnable() {
    @Override
    public void run() {
        planImage.setOnClickListener(v -> new ImageViewer.Builder(getContext(), originalUrls)
            .setStartPosition(0)
            .allowZooming(true)
            .show());
    }
});

But I guess it is a waste of resources ?

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

1 participant