简体   繁体   English

Android-每次我尝试开启应用程式时都会当机

[英]Android - App Crash everytime I try to open it

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. 我是Android的新手,我正在尝试按照教程制作一个简单的应用程序,但是当我尝试使用Android Studio中的模拟器打开该应用程序时,它崩溃并永远不会打开。 In the logcat i get this after "------ beggining of crash" 在logcat中,我在“ ------开始崩溃”之后得到这个

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中有这个:

<?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 ": 错误指向您的xml文件中的第37行,并提供了ID为“ btnSignUp ”的按钮:

Error inflating class info.hoang8f.widget.FButton

Did you include this dependency in your gradle.build file? 您是否在gradle.build文件中包括了此依赖gradle.build

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

Also, make sure that you copied the FButton.java class from Github into your project. 另外,请确保将FButton.java类从Github复制到项目中。 Finally, make sure that you've set the colors in your values folder. 最后,请确保已在values文件夹中设置了颜色。

Try to remove the buttonColor property in FButton because the real error is 尝试删除FButton中的buttonColor属性,因为真正的错误是

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 java.lang.UnsupportedOperationException:无法将索引1处的值转换为颜色:type = 0x5

So you should make sure that your color is correct. 因此,您应确保颜色正确。 Maybe you didn't put # in the color ... 也许您没有在颜色中加# ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM