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 in findNearestByColor #32

Open
uname opened this issue Aug 7, 2015 · 5 comments
Open

NullPointerException in findNearestByColor #32

uname opened this issue Aug 7, 2015 · 5 comments

Comments

@uname
Copy link

uname commented Aug 7, 2015

java.lang.NullPointerException
at com.flask.colorpicker.ColorPickerView.findNearestByColor(ColorPickerView.java:266)
at com.flask.colorpicker.ColorPickerView.onWindowFocusChanged(ColorPickerView.java:123)
at android.view.View.dispatchWindowFocusChanged(View.java:7900)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:972)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:972)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:972)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:972)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:972)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:972)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3133)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

@ghost
Copy link

ghost commented Dec 17, 2015

The problem is that this.renderer.initWith(colorWheelRenderOption) in ColorPickerView is not called and colorCircleList is therefore null. The reason for this is that onWindowFocusChanged which updates the color wheel is not called( e.g. the colorpicker is in a fragment and the fragment is replaced). One workaround that seems to work is:

 ViewTreeObserver vto = colorPickerView.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                colorPickerView.onWindowFocusChanged(true);
                ViewTreeObserver obs = colorPickerView.getViewTreeObserver();
                obs.removeGlobalOnLayoutListener(this);
            }
        });

@riddhishah1989
Copy link

Where I need to apply this code?

I have applied to my Fragment and as well as ColorPickerView.
But still it is giving me same error

at com.flask.colorpicker.ColorPickerView.findNearestByColor(ColorPickerView.java:281)
at com.flask.colorpicker.ColorPickerView.onWindowFocusChanged(ColorPickerView.java:138)

@ghost
Copy link

ghost commented Apr 7, 2016

Calling it in onStart() in a Fragment worked for me.

@riddhishah1989
Copy link

I am not showing that color picker in Alert Dialog. I am loading that view to my Linear layout. will it work fine with it ?
Here below is my code

public ColorPickerDemo(Context context, LinearLayout layout) {
Log.e("ColorPickerDemo", "ColorPickerDemo()");
mContext = context;
builder = new AlertDialog.Builder(context);
pickerContainer = new LinearLayout(context);
pickerContainer.setOrientation(LinearLayout.VERTICAL);
pickerContainer.setGravity(Gravity.CENTER_HORIZONTAL);
defaultMargin = getDimensionAsPx(context, R.dimen.default_slider_margin);
layoutParamsForColorPickerView = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
layoutParamsForColorPickerView.weight = 1;
colorPickerView = new ColorPickerView(context);
wheelType(ColorPickerView.WHEEL_TYPE.CIRCLE);
initialColor(mContext.getResources().getColor(android.R.color.darker_gray));
density(12);
showAlphaSlider(false);
showLightnessSlider(true);
lightnessSliderOnly();
setup();
layout.addView(pickerContainer);

}

@Freshman585
Copy link

@fxlex Thanks! I has already resolve my problem !

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

No branches or pull requests

4 participants