Subash Aryal Subash Aryal - 1 year ago 72
Android Question

Rendering Issue in Android Studio

I am new to Android Studio.And I came accross this problem under activity_main.xml tab . So, How to fix this.I have installed the android studio 1.4.1 bundle offline. Also I can't drag and drop widgets to phone in activity_main.xml.But I can drag and drop in content_main.xml

Rendering Problems
The following classes could not be instantiated:
- (Open Class, Show Exception, Clear Cache)
- (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE

Exception Details

java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
at java.lang.reflect.Constructor.newInstance(
at android.view.LayoutInflater.createViewFromTag(
at android.view.LayoutInflater.inflate(
at android.view.LayoutInflater.inflate(
Copy stack to clipboard

Here is my activity_main.xml in text

<?xml version="1.0" encoding="utf-8"?>
xmlns:tools="" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"

< android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

< android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />


< android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />

Answer Source

Since your MainActivity extends AppCompatActivity, its theme most be from AppCompat. To fix this issue, correct the following:

  1. Open the file app/res/values/styles.xml
  2. Change the following lines in the styles.xml file to look like this:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />


<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />.

They all need to inherit from AppCompat for your chosen layout. See the default working styles.xml file below. You can copy and paste it into your styles.xml file.

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
  1. If you are still having issues, go to the app/manifests/AndroidManifest.xml file and make sure that the value for the theme looks like this android:theme="@style/AppTheme.NoActionBar" or this android:theme="@style/AppTheme" this way they are inheriting from the AppCompat themes as listed above.

See here as well: You need to use a Theme.AppCompat theme (or descendant) with this activity

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download