ausgeorge ausgeorge -4 years ago 934
Android Question

Error inflating class ConstraintLayout

I'm having problems with Android Studio. I recently upgraded my SDK Manager to include;

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


classpath is

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


Project builds fine. Intellisense and documentation works fine. But when I try to run (in debug) the app on my phone I get this error;


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)


I've synced gradle. I've restarted Android Studio. I've cleaned and rebuilt the project.

Any ideas on how to fix this?
thanks!

-edit-
XML looks like this;

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

Answer Source

You should add as below

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

And latest release of ConstraintLayout is 1.0.0

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

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