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

Application crashing... Fatal Exception: java.lang.IllegalStateException #80

Open
panovvitalik opened this issue Nov 2, 2019 · 1 comment

Comments

@panovvitalik
Copy link

panovvitalik commented Nov 2, 2019

Version: 1.0.5

Samsung Galaxy J2 (j2y18lte), Android 7.1

Report 1 of 1

java.lang.IllegalStateException:
at com.jaredrummler.android.colorpicker.ColorPickerDialog.onColorSelected (ColorPickerDialog.java:583)
at com.jaredrummler.android.colorpicker.ColorPickerDialog.access$000 (ColorPickerDialog.java:68)
at com.jaredrummler.android.colorpicker.ColorPickerDialog$2.onClick (ColorPickerDialog.java:190)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage (AlertController.java:167)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6816)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1565)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1453)

@panovvitalik
Copy link
Author

panovvitalik commented Nov 2, 2019

FYI:
Sometimes:
Activity activity = getActivity()
doesn't work correctly.
It can failed when fragment is detached from activity.
Such situations occure very! often (at least in my code for example :-) )
For resolving the issue you can implement next functionality in Your ColorPickerDialog source:

protected ActivityEnabledListener aeListener;

    protected void getAvailableActivity(ActivityEnabledListener listener){
        if (getActivity() == null){
            aeListener = listener;
        } else {
            listener.onActivityEnabled(getActivity());
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        if (aeListener != null){
            aeListener.onActivityEnabled((FragmentActivity) activity);
            aeListener = null;
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        if (aeListener != null){
            aeListener.onActivityEnabled((FragmentActivity) context);
            aeListener = null;
        }
    }
public interface ActivityEnabledListener {
    void onActivityEnabled(FragmentActivity activity);
}

and then replace using getActivity() method with following code:

getAvailableActivity(new ActivityEnabledListener() {
                    @Override
                    public void onActivityEnabled(FragmentActivity activity) {
                        // You can use activity object safely here 
                    }
                });

@panovvitalik panovvitalik changed the title Crash Application crashing... Fatal Exception: java.lang.IllegalStateException: The activity must implement ColorPickerDialogListener Nov 2, 2019
@panovvitalik panovvitalik changed the title Application crashing... Fatal Exception: java.lang.IllegalStateException: The activity must implement ColorPickerDialogListener Application crashing... Fatal Exception: java.lang.IllegalStateException Nov 2, 2019
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