2016-11-25 10 views
-1

CoordinatorLayoutをルート要素に設定すると、Android Studioでプレビューをレンダリングするときに次のエラーが発生します。Android Studio:CoordinatorLayoutを開始できませんでした

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:36) 
    at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:195) 
    at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:189) 
    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:423) 
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465) 
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172) 
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105) 
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186) 
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334) 
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345) 
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858) 
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324) 
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429) 
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389) 
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548) 
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533) 
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966) 
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533) 
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$53(RenderTask.java:659) 
    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) 

以下は私のレイアウトファイルです。

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_authentication" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.domain.projectFile.authentication.AuthenticationActivity" 
    tools:ignore="MissingConstraints"> 
    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


      <FrameLayout 
       android:id="@+id/fragment_frame" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"/> 

    </android.support.design.widget.CoordinatorLayout> 
</android.support.constraint.ConstraintLayout> 

そして、これは私がConstraintLayoutCoordinatorLayoutをラップしようとした

apply plugin: 'com.android.application' 
    android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.1" 
    defaultConfig { 
     applicationId "com.domain.projectFile" 
     minSdkVersion 15 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 


    //Added dependencies here 

    //Dependency for Retrofit and Gson Converter (related to login/register activity) 
    compile 'com.squareup.retrofit2:retrofit:2.0.0' 
    compile 'com.squareup.retrofit2:converter-gson:2.0.0' 

    //Dependency for Design Support Library for UI 

    compile 'com.squareup.retrofit2:retrofit:2.0.0' 
    compile 'com.squareup.retrofit2:converter-gson:2.0.0' 
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4' 
    compile 'com.android.support:support-v4:25.0.1' 
    compile 'com.android.support:appcompat-v7:25.0.1' 
    compile 'com.android.support:support-annotations:25.0.1' 

    compile 'com.android.support:recyclerview-v7:25.0.1' 
    compile 'com.android.support:design:25.0.1' 

    testCompile 'junit:junit:4.12' 
} 

私のbuild.gradleです。 ConstraintLayoutLinearLayoutに変更した後も同じことを試しましたが、これはConstraintLayoutが問題であった可能性があると考えたためです。

問題が発生している可能性がありますか?

編集1:ここでのstyles.xmlファイル:

 <resources> 
    <!-- Base application theme. --> 
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
    </style> 
</resources> 
+0

uがあまりにもYOUTのstyles.xmlを投稿することができます....あなたのアプリに問題があるように思われるテーマ – Ak9637

+0

はあなたのstyles.xmlを投稿 –

+0

@DeepakSachdevaは、ファイルをチェックアウトし、Ak9637 @ファイル – user3519023

答えて

0

Theme.AppCompat.Light.DarkActionBarに変更しますstyle内部themeあなたのスタイルシートに <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"

+0

私はそれがうまくいくと思います。そんなにありがとう!簡単な質問ですが、ConstraintLayoutエディタの画面上に「CoordinatorLayout/activety_authentication」と表示されていますが、それは正常ですか? – user3519023

+0

私は拘束レイアウトに慣れていませんが、私が知っている限り...制約レイアウトはまだまだ盛り上がっています...それを試してみてください.....しかし、安定したrealeaseまでメインのアプリケーションでそれを使用しないでください – Ak9637

+0

私は安定版が見つかっても見つからなかったときに検索しようとしました。それは今からまだ遠いと思いますか? – user3519023

0

をこの変更を試してみてください。

<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> 
+0

これはうまくいきました。私はそのトリックが親を編集することだったと思う。ありがとうございました! – user3519023

0

styles.xmlで親を変更します。これを試して。

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <item name="windowNoTitle">true</item> 
     <item name="windowActionBar">false</item> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="windowActionModeOverlay">true</item> 
</style> 
関連する問題