0

I'm new in Android and i'm trying to make a simple app following a tutorial, but when I try to open the app using the emulator from Android Studio, it crash and never opens. In the logcat i get this after "------ beggining of crash"

2018-09-27 14:59:36.362 5807-5807/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: corner.yabej.corner12, PID: 5807
    java.lang.RuntimeException: Unable to start activity ComponentInfo{corner.yabej.corner12/corner.yabej.corner12.MainActivity}: android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class info.hoang8f.widget.FButton
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class info.hoang8f.widget.FButton
     Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class info.hoang8f.widget.FButton
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.view.LayoutInflater.createView(LayoutInflater.java:645)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
        at corner.yabej.corner12.MainActivity.onCreate(MainActivity.java:18)
        at android.app.Activity.performCreate(Activity.java:6679)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
        at android.content.res.TypedArray.getColor(TypedArray.java:463)
        at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
        at info.hoang8f.widget.FButton.<init>(FButton.java:52)

And I have this in the Main Activity 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:background="@drawable/background"
    tools:context=".MainActivity">

    <LinearLayout
        android:orientation="vertical"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:src="@drawable/twelve"
            android:layout_width="200dp"
            android:layout_height="200dp" />

        <TextView
            android:gravity="center"
            android:id="@+id/txtSlogan"
            android:text="@string/slogan"
            android:textColor="@android:color/white"
            android:layout_width="200dp"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:weightSum="2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <info.hoang8f.widget.FButton
            android:id="@+id/btnSignUp"
            android:text="Sign Up"
            android:textColor="@android:color/white"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            app:buttonColor="@color/btnSignUp"
            app:shadowColor="@android:color/black"
            app:shadowEnabled="true"
            app:shadowHeight="5dp"
            app:cornerRadius="4dp"
            />

        <info.hoang8f.widget.FButton
            android:id="@+id/btnSignIn"
            android:text="Sign In"
            android:textColor="@android:color/white"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            app:buttonColor="@color/btnSignActive"
            app:shadowColor="@android:color/black"
            app:shadowEnabled="true"
            app:shadowHeight="5dp"
            app:cornerRadius="4dp"
            />

    </LinearLayout>
</RelativeLayout>

Anyone knows what is going on? I did everything just like the tutorial.

Bruno
  • 3,872
  • 4
  • 20
  • 37
  • Possible duplicate of [Binary XML file line #0: Error inflating class ](https://stackoverflow.com/questions/47221195/binary-xml-file-line-0-error-inflating-class-unknown) – TheWanderer Sep 27 '18 at 20:10
  • Caused by: android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class info.hoang8f.widget.FButton – Nik Sep 27 '18 at 20:13
  • https://stackoverflow.com/questions/46947665/error-inflating-class-info-hoang8f-widget-fbutton – varunkr Sep 27 '18 at 20:19

3 Answers3

1

The error is pointing to line #37 in your xml file, with the button that you have given an ID of "btnSignUp":

Error inflating class info.hoang8f.widget.FButton

Did you include this dependency in your gradle.build file?

dependencies {
    compile 'info.hoang8f:fbutton:1.0.5'
}

Also, make sure that you copied the FButton.java class from Github into your project. Finally, make sure that you've set the colors in your values folder.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
shagberg
  • 2,427
  • 1
  • 12
  • 23
0

Try to remove the buttonColor property in FButton because the real error is

Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
        at android.content.res.TypedArray.getColor(TypedArray.java:463)
        at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
        at info.hoang8f.widget.FButton.<init>(FButton.java:52)
0

The error is from this code:

mButtonColor = typedArray.getColor(attr, R.color.fbutton_default_color);

and the error is:

java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5

So you should make sure that your color is correct. Maybe you didn't put # in the color ...

Norutan
  • 1,480
  • 2
  • 14
  • 27