doing a tutorial created a new project at startup gives an error java.lang.RuntimeException: Unable to start activity Binary XML file line # 0: Error inflating class android.support.constraint.ConstraintLayout

LifeCycleActivity.java

package android.and08.lifecycle; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; public class LifeCycleActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_life_cycle); Log.e(getClass().getSimpleName(), "\"onCreate\" durchlaufen"); } @Override protected void onStart(){ super.onStart(); Log.e(getClass().getSimpleName(), "\"onStart\" durchlaufen"); } @Override protected void onResume(){ super.onResume(); Log.e(getClass().getSimpleName(), "\"onResume\" durchlaufen"); } @Override protected void onRestart(){ super.onRestart(); Log.e(getClass().getSimpleName(), "\"onRestart\" durchlaufen"); } @Override protected void onPause(){ super.onPause(); Log.e(getClass().getSimpleName(), "\"onPause\" durchlaufen"); } @Override protected void onStop(){ super.onStop(); Log.e(getClass().getSimpleName(), "\"onStop\" durchlaufen"); } @Override protected void onDestroy(){ super.onDestroy(); Log.e(getClass().getSimpleName(), "\"onDestroy\" durchlaufen"); } } 

activity_life_cycle.xml

 <?xml version="1.0" encoding="utf-8"?> <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:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="android.and08.lifecycle.LifeCycleActivity"> <EditText android:id="@+id/et_lifecycle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> 

2nd option activity_life_cycle.xml

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="android.and08.lifecycle.LifeCycleActivity"> <EditText android:id="@+id/et_lifecycle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </RelativeLayout> 

same problem: java.lang.RuntimeException: Unable to start activity ComponentInfo {android.and08.lifecycle / android.and08.lifecycle. LifeCycleActivity}: android.view.InflateException: Binary XML file line # 0: Binary XML file line # 0: Error inflating class android.widget.RelativeLayout

build.gradle (Modulle app)

 apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "android.and08.lifecycle" minSdkVersion 16 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' } 

Closed due to the fact that off-topic party Qwertiy Jan 31 '18 at 21:38 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Qwertiy
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • attach to build.gradle issue - TimurVI
  • Try in studio InvalidateCache and Restart to make. - Yuriy SPb

2 answers 2

Try adding build.gradle ( Module: app ) to the dependencies {... block

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

The latest version can be found here.

  • does not work; the same mistake - Lena Kosareva
  • one
    @LenaKosareva: updated sync now ? - TimurVI
  • synchronized project - Lena Kosareva
  • @LenaKosareva: helped? - TimurVI
  • no, if you change to RelativeLayout as in the textbook, the exact same error - Lena Kosareva

I did something wrong when I created the project, I re-created it and it all worked. Thank you TimurVI

  • You better do not write thanks to the answer to your question, and tick the answer @TimurVI if it helped you. - Sviat Volkov