2017-02-28 109 views
2

我遇到Android Studio問題。我最近升級了我的SDK管理器以包含;充氣類錯誤ConstraintLayout

compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5' 

類路徑是

classpath 'com.android.tools.build:gradle:2.2.3' 

項目構建的罰款。智能感知和文檔工作正常。但是,當我嘗試運行(在調試中)我的手機上的應用程序時,我得到這個錯誤;

Caused by: android.view.InflateException: Binary XML file line #2: 
Binary XML file line #2: Error inflating class ConstraintLayout 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:443) 
        at android.app.Activity.setContentView(Activity.java:2172) 

我已經同步了gradle。我已重新啓動Android Studio。我清理並重建了這個項目。

有關如何解決此問題的任何想法? 謝謝!

-edit- XML看起來像這樣;

<ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/PLAY_PARENT" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/greenfelt2" 
android:padding="0dp"> 
+0

添加XML代碼。 –

回答

10

您應該添加如下

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/PLAY_PARENT" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/greenfelt2" 
android:padding="0dp"> 

compile 'com.android.support.constraint:constraint-layout:1.0.2'

有關最新版本檢查https://developer.android.com/training/constraint-layout/index.html

+0

這樣做會導致此錯誤; 「使用版本1.0.0-beta5時,這個版本的約束庫已經過時了,它只是一個該死的intellisense錯誤,它仍然會建立並運行......(當我看到那個錯誤時,我甚至沒有嘗試運行......) 。感謝。 – ausgeorge

+0

查看這個項目更多關於ConstraintLayout https://github.com/Arjun-sna/android-constraintlayout-demo – arjun

+0

如果你有警告,請使用當前版本:'com.android.support.constraint:constraint-佈局:1.0.2' – chntgomez