16

I just downloaded and started learning android L material design api. Whenever I use CardView in my activity it gives me this error Failed to find style with id 0x7f070001 in current theme.

This is my xml layout :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res/com.flip.tesla"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.flip.tesla.MainActivity$PlaceholderFragment" >

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:cardElevation="10dp" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="15sp" />
</android.support.v7.widget.CardView>

</RelativeLayout>

And this is my manifest file :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

and this is the exact message it displays :

Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.

Failed to find style with id 0x7f070001 in current theme

EDIT : So I restarted eclipse this is the new message it displays.

Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup Exception details are logged in Window > Show View > Error Log The following classes could not be instantiated: - android.support.v7.widget.CardView

any ideas on what it means?

Nikhil Jain
  • 193
  • 1
  • 8

6 Answers6

7

It's an issue related with Gradle sync. Try clicking the refresh button in the toolbar

  • 1
    I had this problem and Gradle sync did not fix the issue until I change the `compileSdkVersion` to a different version and then change it back to where I want it – CrandellWS Oct 28 '15 at 08:26
  • 2
    It is annoying to see such minor glitches. **Cleaning the project** followed by a **rebuild** worked for me. – vyi Feb 21 '17 at 17:20
1

Try running the application and see if it shows the output

user2779311
  • 1,688
  • 4
  • 23
  • 31
1

put android.support.v7.widget.CardView as your parent layout instead of RelativeLayout,

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_gravity="center"
 card_view:cardCornerRadius="4dp" >

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    android:orientation="vertical"
    android:weightSum="100" >
Anu Martin
  • 711
  • 1
  • 9
  • 20
0

try to use this code in your activity style

<style name="StyledIndicators" parent="@android:style/Theme.Light">
    <item name="vpiCirclePageIndicatorStyle">@style/CustomCirclePageIndicator</item>
</style>

<style name="CustomCirclePageIndicator">
    <item name="fillColor">#000000</item>
    <item name="strokeColor">#000000</item>
    <item name="strokeWidth">1dp</item>
    <item name="radius">6dp</item>
    <item name="centered">true</item>
</style>

see this link failed-to-find-style-vpicirclepageindicatorstyle

Community
  • 1
  • 1
hmir
  • 97
  • 2
  • 7
0

This solution worked for me:

Go to File -> Invalidate Caches / Restart and click on Invalidate and Restart.

S. B.
  • 186
  • 1
  • 12
-1

Go to Build> Rebuild Project