Java – Android Studio: Unfortunately “my App” has stopped

Android Studio: Unfortunately “my App” has stopped… here is a solution to the problem.

Android Studio: Unfortunately “my App” has stopped

I’m new to Android development. After writing my code and running the debugger, my application fails to open with “Unfortunately the application has stopped”.

Here is my stack trace.

07-19 14:16:07.562 10834-10834/com.afiqah.fyp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.afiqah.fyp, PID: 10834
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.afiqah.fyp/com.afiqah.fyp.MainActivity}: android.view.InflateException: Binary XML file line #43: Binary XML file line #43: Error inflating class info.hoang8f.widget.FButton
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
    at android.app.ActivityThread.access$900(ActivityThread.java:153)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5451)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: android.view.InflateException: Binary XML file line #43: Binary XML file line #43: Error inflating class info.hoang8f.widget.FButton
    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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at com.afiqah.fyp.MainActivity.onCreate(MainActivity.java:17)
    at android.app.Activity.performCreate(Activity.java:6323)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
    at android.app.ActivityThread.access$900(ActivityThread.java:153) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5451) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
 Caused by: android.view.InflateException: Binary XML file line #43: Error inflating class info.hoang8f.widget.FButton
    at android.view.LayoutInflater.createView(LayoutInflater.java:645)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
    at com.afiqah.fyp.MainActivity.onCreate(MainActivity.java:17) 
    at android.app.Activity.performCreate(Activity.java:6323) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
    at android.app.ActivityThread.access$900(ActivityThread.java:153) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5451) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at android.view.LayoutInflater.createView(LayoutInflater.java:619)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
    at com.afiqah.fyp.MainActivity.onCreate(MainActivity.java:17) 
    at android.app.Activity.performCreate(Activity.java:6323) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
    at android.app.ActivityThread.access$900(ActivityThread.java:153) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5451) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
 Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x5
    at android.content.res.TypedArray.getColor(TypedArray.java:451)
    at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
    at info.hoang8f.widget.FButton.<init>(FButton.java:52)
    at java.lang.reflect.Constructor.newInstance(Native Method) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
    at com.afiqah.fyp.MainActivity.onCreate(MainActivity.java:17) 
    at android.app.Activity.performCreate(Activity.java:6323) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
    at android.app.ActivityThread.access$900(ActivityThread.java:153) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5451) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

This is my activity_main.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:background="@drawable/back"
tools:context=". MainActivity"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="123dp"
    android:orientation="vertical">

<ImageView
        android:layout_width="321dp"
        android:layout_height="158dp"
        android:contentDescription="TODO"
        android:src="@drawable/logo" />

<TextView
        android:id="@+id/txtSlogan"
        android:layout_width="match_parent"
        android:layout_height="106dp"
        android:gravity="center"
        android:text="@string/slogan"
        android:textColor="@android:color/black" />

</LinearLayout>

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

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

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

</LinearLayout>

This is my AndroidManifest .xml

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=". MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

This is my MainActivity .java

    public class MainActivity extends AppCompatActivity {

Button btnSignIn,btnSignUp;
    TextView txtSlogan;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

btnSignIn = (Button)findViewById(R.id.btnSignIn);
        btnSignUp = (Button)findViewById(R.id.btnSignUp);

txtSlogan = (TextView)findViewById(R.id.txtSlogan);
        Typeface face = Typeface.createFromAsset(getAssets(),"fonts/Nabila.ttf");
        txtSlogan.setTypeface(face);

btnSignIn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){

}
        });

btnSignUp.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){

}
        });
    }
}

Does anyone know what my problem is? I need to work it out because this is my last year project.

Solution

Latest Update:

I

think I found the answer, although I haven’t tested it yet, but it’s the most recent commit and people have proven it works, check out jd-alexander’s review here

https://github.com/hoang8f/android-flat-button/issues/41#issuecomment-350491965

Also, check out the modified repo of Hoang8F’s flat android button here

https://github.com/jd-alexander/android-flat-button

If you’re a little confused about how to implement it, you can see the review of panpan1997 here

https://github.com/hoang8f/android-flat-button/issues/41#issuecomment-375702859

End

Old posts start here

I’m sure you’re following the “Eat-it” app tutorial on youtube. I had the same challenge, and I was equally skeptical that it had to do with

info.hoang8f.widget.FButton

What I tried was to go into my gradle file (application) and comment out the call to the api, and also change every occurrence of it in the app from info.hoang8f.widget.FButton to button so I could have no buttons, no more errors.

Also check your styles.xml file, if there is an error with the “theme”, if not, try checking the code. If any of your files throw any errors, it should tell you.

If all else fails, check here< a href="https://stackoverflow.com/questions/46947665/error-inflating-class-info-hoang8f-widget-fbutton" rel="noreferrer noopener nofollow">Error inflating class info.hoang8f.widget.FButton

If you are using Android Studio v3, you may need to change your Gradle version, and your Gradle version will also show as 3, so you can downgrade it in the build.gradle (project) file, for example:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

 NOTE: Do not place your application dependencies here; they belong
         in the individual module build.gradle files
    }
}

Related Problems and Solutions