无法为颜色首选项选择器Android

时间:2016-10-19 13:31:26

标签: android android-resources color-picker

我正在开发一款Android应用。在我的应用程序中,我需要创建颜色选择器。美丽的颜色选择器。所以我正在使用这个选择器 - https://android-arsenal.com/details/1/4401。我正在做的是按钮的点击监听器上的简单,开放的颜色选择器。但是当我点击按钮时抛出错误。

这是在活动中打开选择器的代码

private void openCaptionTfColorPicker()
    {
        new ColorDialog.Builder(this)
                .setColorShape(ColorShape.CIRCLE) //CIRCLE or SQUARE
                .setColorChoices(R.array.color_choices) //an array of colors
                .setSelectedColor(Color.GREEN) //the checked color
                .setTag(TAG_TF_COLOR_PICKER) // tags can be useful when multiple components use the picker within an activity
                .show();
    }

我的活动实现了ColorDialog.OnColorSelectedListener

这是我在array.xml中的color_choices数组

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name="color_choices">
        <item>@android:color/black</item>
        <item>@android:color/white</item>
    </string-array>
</resources>

当我点击按钮

时,这是logcat中的错误
  

致命的例外:主要                                                                                               过程:memegenerator.waiyanhein.com.memegenerator,PID:17860                                                                                               java.lang.NullPointerException:尝试调用虚方法&#39; int   java.util.ArrayList.size()&#39;在null对象引用上                                                                                                   在   memegenerator.waiyanhein.com.adapter.InstalledTemplatesAdapter.getItemCount(InstalledTemplatesAdapter.java:92)                                                                                                   在   android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:2938)                                                                                                   在   android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2904)                                                                                                   在   android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)                                                                                                   在android.view.View.layout(View.java:16636)                                                                                                   在android.view.ViewGroup.layout(ViewGroup.java:5437)                                                                                                   在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)                                                                                                   在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)                                                                                                   在android.widget.LinearLayout.onLayout(LinearLayout.java:1495)                                                                                                   在android.view.View.layout(View.java:16636)                                                                                                   在android.view.ViewGroup.layout(ViewGroup.java:5437)                                                                                                   在android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695)                                                                                                   在android.view.View.layout(View.java:16636)                                                                                                   在android.view.ViewGroup.layout(ViewGroup.java:5437)                                                                                                   在android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)                                                                                                   在android.view.View.layout(View.java:16636)                                                                                                   在android.view.ViewGroup.layout(ViewGroup.java:5437)                                                                                                   在android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)                                                                                                   在android.widget.FrameLayout.onLayout(FrameLayout.java:273)                                                                                                   在android.view.View.layout(View.java:16636)                                                                                                   在android.view.ViewGroup.layout(ViewGroup.java:5437)                                                                                                   在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)                                                                                                   在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)                                                                                                   在android.widget.LinearLayout.onLayout(LinearLayout.java:1495)                                                                                                   在android.view.View.layout(View.java:16636)                                                                                                   在android.view.ViewGroup.layout(ViewGroup.java:5437)                                                                                                   在android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)                                                                                                   在android.widget.FrameLayout.onLayout(FrameLayout.java:273)                                                                                                   在android.view.View.layout(View.java:16636)                                                                                                   在android.view.ViewGroup.layout(ViewGroup.java:5437)                                                                                                   在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)                                                                                                   在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)                                                                                                   在android.widget.LinearLayout.onLayout(LinearLayout.java:1495)                                                                                                   在android.view.View.layout(View.java:16636)                                                                                                   在android.view.ViewGroup.layout(ViewGroup.java:5437)                                                                                                   在android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)                                                                                                   在android.widget.FrameLayout.onLayout(FrameLayout.java:273)                                                                                                   在   com.android.internal.policy.PhoneWindow $ DecorView.onLayout(PhoneWindow.java:2678)                                                                                                   在android.view.View.layout(View.java:16636)                                                                                                   在android.view.ViewGroup.layout(ViewGroup.java:5437)                                                                                                   在android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)                                                                                                   在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)                                                                                                   在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)                                                                                                   在   android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6013)                                                                                                   在   android.view.Choreographer $ CallbackRecord.run(Choreographer.java:858)                                                                                                   在android.view.Choreographer.doCallbacks(Choreographer.java:670)                                                                                                   在android.view.Choreographer.doFrame(Choreographer.java:606)                                                                                                   在   android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:844)                                                                                                   在android.os.Handler.handleCallback(Handler.java:739)                                                                                                   在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                                   在android.os.Looper.loop(Looper.java:148)                                                                                                   在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                                                   at java.lang.reflect.Method.invoke(Native Method)                                                                                                   在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                                   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我能想到的是,我的色彩资源阵列出了问题。为什么会抛出这个错误?

0 个答案:

没有答案