kristiyanP / colorpicker

A simple color picker library for Android
Apache License 2.0
193 stars 43 forks source link

error new version 1.1.7 #18

Closed hvar90 closed 6 years ago

hvar90 commented 7 years ago

with 1.1.5 works well but it fail with 1.1.7

java.lang.NullPointerException at
petrov.kristiyan.colorpicker.ColorPicker.dismissDialog(ColorPicker.java:502)
at petrov.kristiyan.colorpicker.ColorPicker.setOnFastChooseColorListener(ColorPicker.java:355)
at myPackage.ChatActivity.onOptionsItemSelected(ChatActivity.java:1257)

final ColorPicker colorPicker = new ColorPicker(this);
            final int init_color;
            if (Build.VERSION.SDK_INT < 23)
                init_color=getResources().getColor(R.color.color1);
            else
                init_color=getResources().getColor(R.color.color1,getTheme());
            colorPicker.setTitle(getString(R.string.chooseColor));
            colorPicker.setRoundColorButton(true);
            colorPicker.setColors(R.array.color_chat_values);
          //////here is the bug//////// 
            colorPicker.setOnFastChooseColorListener(new ColorPicker.OnFastChooseColorListener() {
                @Override
                public void setOnFastChooseColorListener(int position, int color) {
                    SharedPreferences sharedPreferences =
                            PreferenceManager.getDefaultSharedPreferences(ChatActivity.this);
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    //posicion empieza desde cero
                    editor.putInt(QuickstartPreferences.THEME_CHAT,position);
                    editor.putInt(QuickstartPreferences.COLOR_CHAT,color);
                    editor.commit();
                    recreate();
                }
                @Override
                public void onCancel(){
                    // put code
                }
            }).setDefaultColorButton(
                    PreferenceManager.getDefaultSharedPreferences(this)
                            .getInt(QuickstartPreferences.COLOR_CHAT,init_color)).setColumns(4).show();
naishadhparmar commented 6 years ago

Can you show what recreate() does?

hvar90 commented 6 years ago

recreate is a method from Android Framework https://developer.android.com/reference/android/app/Activity.html#recreate%28%29