1

I am having a problem in my simple application. I am following the tutorial from the android website. There's a part that they use Holo Light as a theme. But my problem is I am getting an error when I choose this theme. I also looked at this topic and tried some of the approaches but still I am getting the same error.

Here's my errors:

java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34) at android.support.design.widget.CoordinatorLayout.(CoordinatorLayout.java:178) at android.support.design.widget.CoordinatorLayout.(CoordinatorLayout.java:172) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:458) at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:170) at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:103) at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:168) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:247) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:171) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:394) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:223) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498) at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72) at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610) at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607) at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:362) at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607) at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629) at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:480) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310) at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227) at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217) at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) at com.intellij.util.Alarm$Request$1.run(Alarm.java:351) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

Here's my files:

styles.xml

<resources>

    <!-- 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>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

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

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

</resources>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.flax.myfirstapp">

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".DisplayMessageActivity"
            android:label="@string/title_activity_display_message"
            android:parentActivityName=".MyActivity"
            android:theme="@style/AppTheme.NoActionBar">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.flax.myfirstapp.MyActivity" />
        </activity>
    </application>

</manifest>

MyActivity.java

package com.flax.myfirstapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Intent;
import android.widget.EditText;

public class MyActivity extends AppCompatActivity {
......

Can you help me with this? I am extremely new in Android Development. I am stuck since yesterday with this errors. :(

Here's the image of my file structure and also the error:

enter image description here

Community
  • 1
  • 1
Jerielle
  • 7,144
  • 29
  • 98
  • 164

2 Answers2

3

Change

<style name="AppTheme.NoActionBar">

to

<style name="Theme.AppCompat.Light.NoActionBar"> 

and set it

android:theme="@style/Theme.AppCompat.Light.NoActionBar"
M D
  • 47,665
  • 9
  • 93
  • 114
2

I'm having the same issue:

enter image description here

Since your project seems to be a new project with the default configuration, and you already have:

<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

And also:

android:theme="@style/AppTheme.NoActionBar">

In your Manifest, it seems to be a bug or problem with Android Studio and i hope it will fixed soon.

But with our codes, everything is okay, no problem, i will report this to Google.

And onething more, because that layout is coming from the main_layout.xml with this line:

<include layout="@layout/content_main" />

It should be the reason, but, i've tried that and same issue.

But, for now, if you need to design that Layout, you may want to change the Theme for your Android Studio's Preview to a Light with DarkActionbar.

Or change the theme to AppTheme, like this:

enter image description here

It should work then.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • Thanks for the explanation. I can only preview using the `AppTheme` only. Whenever I tried different theme I always got those errrors. – Jerielle Feb 03 '16 at 08:11
  • Yes, because it's a `Layout` and it's coming from `main_content.xml` and it doesn't have any styles, we need to add an inheritance like this case from the main layout – ʍѳђઽ૯ท Feb 03 '16 at 08:12
  • Ok thanks for the info. Maybe I should stop studying for now until there is a fix in this error. If you found some solution with this one please send me the link. Thanks. :) – Jerielle Feb 03 '16 at 08:14
  • Ill try to look for some solutions too. :) – Jerielle Feb 03 '16 at 08:16
  • There is also a canary channel for newest version of android studio, i think they will fix these problems in the newest version, see: http://tools.android.com/download/studio/canary the latest preview is almost finished, they will realased the new version soon, you can use that `AppTheme` for now or downloading the latest version from canary channel.goodluck :) – ʍѳђઽ૯ท Feb 03 '16 at 08:17
  • Is it still fine to continue my study even if this error still existing? – Jerielle Feb 03 '16 at 08:19
  • 1
    Well, these things are normal and that's because it's just a layout which comes from main layout, you could even use that layout in the main layout without these errors:) by removing this line and designing your own layout(not recommended, and no need to stop:) ) **:** `` – ʍѳђઽ૯ท Feb 03 '16 at 08:20