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.
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.
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)
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 ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.