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

Can't render SpectrumPalette in Android Studio because of NPE on computeHeight #35

Closed
ripern opened this issue Dec 22, 2016 · 2 comments

Comments

@ripern
Copy link

ripern commented Dec 22, 2016

Android Studio cannot render SpectrumPalette in its Preview
I've had this problem with v0.6 for several months, today I switched to 0.7 in hope it had been fixed but same thing, stacktrace:

java.lang.NullPointerException   at com.thebluealliance.spectrum.SpectrumPalette.computeHeight(SpectrumPalette.java:186)   at com.thebluealliance.spectrum.SpectrumPalette.onMeasure_Original(SpectrumPalette.java:153)   at com.thebluealliance.spectrum.SpectrumPalette.onMeasure(SpectrumPalette.java:-1)   at android.view.View.measure(View.java:19731)   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)   at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)   at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)   at android.view.View.measure(View.java:19731)   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)   at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)   at android.support.design.widget.CoordinatorLayout.onMeasure_Original(CoordinatorLayout.java:786)   at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:-1)   at android.view.View.measure(View.java:19731)   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)   at android.view.View.measure(View.java:19731)   at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)   at android.view.View.measure(View.java:19731)

Does it not support being a child of a CoordinatorLayout?
I have: (I tried formatting but never came out better than this, sorry)

`
<android.support.design.widget.CoordinatorLayout
android:id="@+id/prefsCoordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="?attr/actionBarSize"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <com.thebluealliance.spectrum.SpectrumPalette
            android:id="@+id/color_palette"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:spectrum_autoPadding="true"/>

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>
`

@ripern ripern changed the title Rendering problems in Android Studio because of NPE on computeHeight Can't rendering SpectrumPalette in Android Studio because of NPE on computeHeight Dec 22, 2016
@ripern ripern changed the title Can't rendering SpectrumPalette in Android Studio because of NPE on computeHeight Can't render SpectrumPalette in Android Studio because of NPE on computeHeight Dec 22, 2016
@nwalters512
Copy link
Member

That shouldn't be throwing exceptions; I'll release a fix for that. Regardless, the layout previewer won't be of much use if you set the colors programmatically. If you want to see anything other than an empty box in the previewer, you'll have to provide the colors array with the spectrum_colors attribute.

Coincidentally, I think I found a bug in the Layout Editor: a colors array set via an XML attribute isn't properly being provided in preview mode. Relevant bug is here: https://code.google.com/p/android/issues/detail?id=230875

@ripern
Copy link
Author

ripern commented Dec 27, 2016

Thanks for the super quick response and fix!

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

2 participants