2

I am getting this error, could you help me please.

Unable to start activity ComponentInfo
{com.kaniar.tappy_defender/com.kaniar.tappy_defender.MainActivity}: 
android.view.InflateException: 
Binary XML file line #2: 
Error inflating class android.support.design.widget.CoordinatorLayout

MainActivity.java

package com.kaniar.tappy_defender;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity implements View.OnClickListener {

// This is the entry point of the game
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set the UI layout as the view
    setContentView(R.layout.activity_main);

    // Get a reference to the playButton in the layout
    final Button playButton = (Button)findViewById(R.id.playButton);

    // Listen for clicks
    playButton.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    // Must be the Play button
    // Create a new Intent object
    Intent intent = new Intent(this, GameActivity.class);

    // Start the GameActivity class via the Intent
    startActivity(intent);

    // Now shut this activity down
    finish();
}
}

XML file

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout   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:fitsSystemWindows="true"
tools:context="com.kaniar.tappy_defender.MainActivity"
android:background="@drawable/background">

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

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

LogCat output

02-11 18:24:07.980 21999-21999/com.kaniar.tappy_defender E/AndroidRuntime: FATAL EXCEPTION: main
                                                                           Process: com.kaniar.tappy_defender, PID: 21999
                                                                       java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kaniar.tappy_defender/com.kaniar.tappy_defender.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                           at android.os.Looper.loop(Looper.java:193)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5333)
                                                                           at java.lang.reflect.Method.invokeNative(Native Method)
                                                                           at java.lang.reflect.Method.invoke(Method.java:515)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
                                                                           at dalvik.system.NativeStart.main(Native Method)
                                                                        Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
                                                                           at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                           at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341)
                                                                           at android.app.Activity.setContentView(Activity.java:1948)
                                                                           at com.kaniar.tappy_defender.MainActivity.onCreate(MainActivity.java:17)
                                                                           at android.app.Activity.performCreate(Activity.java:5343)
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429) 
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                           at android.os.Looper.loop(Looper.java:193) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5333) 
                                                                           at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                           at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                           at dalvik.system.NativeStart.main(Native Method) 
                                                                        Caused by: java.lang.reflect.InvocationTargetException
                                                                           at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                           at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                                                                           at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                           at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341) 
                                                                           at android.app.Activity.setContentView(Activity.java:1948) 
                                                                           at com.kaniar.tappy_defender.MainActivity.onCreate(MainActivity.java:17) 
                                                                           at android.app.Activity.performCreate(Activity.java:5343) 
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331) 
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429) 
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                           at android.os.Looper.loop(Looper.java:193) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5333) 
                                                                           at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                           at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                           at dalvik.system.NativeStart.main(Native Method) 
                                                                        Caused by: 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.<init>(CoordinatorLayout.java:178)
                                                                           at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:172)
                                                                           at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                           at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                                                                           at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                           at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341) 
                                                                           at android.app.Activity.setContentView(Activity.java:1948) 
                                                                           at com.kaniar.tappy_defender.MainActivity.onCreate(MainActivity.java:17) 
                                                                           at android.app.Activity.performCreate(Activity.java:5343) 
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331) 
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429) 
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                           at android.os.Looper.loop(Looper.java:193) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5333) 
                                                                           at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                           at java.lang.reflect.Method.invoke(Method.java:515)

I don't really know what happens, I can build the project but when I run the app on a phone or a simulator, I got this ! If someone know a solution, it will be awesome !

2 Answers2

1

Try to change Activity to AppCompatAvtivity in your MainActivity extension.

If still don't work change also the parent theme to an AppTheme

<style name="Base.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Spirrow
  • 1,120
  • 6
  • 18
  • In your style.xml, you should have it but with a different parent maybe, you have to change its parent to one of AppCompat, like the one I have chosen – Spirrow Feb 11 '16 at 15:21
  • You also need this dependence compile 'com.android.support:design:22.2.0' and compile 'com.android.support:appcompat-v7:23.1.1' (I was assuming you had it) – Spirrow Feb 11 '16 at 15:26
  • I found the solution! It was because I have deleted : android:theme="@style/Theme.AppCompat" in AndroidManifest.xml Why I did that ? Because I wanted to put also this line : android:theme="@android:style/Theme.NoTitleBar.Fullscreen" But know my question is how I could keep the both in the same file ? – Totof TonMomon Feb 11 '16 at 15:35
  • You have to create a new style in your styles.xml like this one: And add this new style in your manifest intead of the one you have – Spirrow Feb 11 '16 at 16:10
  • If your problem is resolved, mark the answer as correct, please – Spirrow Feb 11 '16 at 23:04
0

I found the solution and it's to create the following theme in your styles-v21.xml (it should already be there if you imported the sample files, but if it is not there, please create it):

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style

> And calling it in the manifest, in the main activity part, as follows (delete the line I highlighted earlier and put this in its place):

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

thios should solve the probleme.

InflateException Error inflating class android.support.design.widget.CoordinatorLayout

Community
  • 1
  • 1