Hello dear stackoverflower,
In my project, i am using the new \"android design library\". The problem is, that there is a runtime exception which says(Im trying to c
Had the same issue because have used getApplicationContext()
instead of Activity
to retrieve LayoutInflater
and inflate item view for list adapter.
I was using a custom attribute in attrs.xml and a customview. I ran into this problem as I didn't specify theme:
attribute in the custom view. Quick look of how the files look
attrs.xml
<resources>
<attr name="textColorPrimary" format="reference" />
...
</resources>
customview.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tvText"
style="@style/TitleBlackThin"
android:theme="@style/AppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="16dp"
android:text="@string/text" />
In my styles.xml, I extended my style to use AppTheme
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="textColorPrimary">@color/black</item>
</style>
...
<style name="TitleBlackThin">
<item name="android:textSize">20sp</item>
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">?textColorPrimary</item>
</style>
...
</resources>
The culprit here was custom attribute ?textColorPrimary. As I didn't define AppTheme in the customview, it wasn't able to determine how to load textColorPrimary. By android:theme="@style/AppTheme", this got fixed))
Make sure your theme .
My theme :
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#1565C0</item>
<item name="colorAccent">#E91E63</item>
</style>
In my case, I had an error at setContentView(R.layout.my_layout)
.
In my_layout
, I was using app:errorEnabled="true"
in a TextInputLayout
which caused the error. Removed that line, and it worked.