请解决此错误,我不知道我在想什么

时间:2018-12-06 17:53:46

标签: android

/com.example.pawan.madc E / AndroidRuntime:致命异常:main     流程:com.example.pawan.madc,PID:23315     java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.pawan.madc / com.example.pawan.madc.MainActivity}:android.view.InflateException:二进制XML文件第49行:膨胀类android.support的错误.design.widget.FloatingActionButton         在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)         在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614)         在android.app.ActivityThread.access $ 800(ActivityThread.java:178)         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1470)         在android.os.Handler.dispatchMessage(Handler.java:111)         在android.os.Looper.loop(Looper.java:194)         在android.app.ActivityThread.main(ActivityThread.java:5643)         在java.lang.reflect.Method.invoke(本机方法)         在java.lang.reflect.Method.invoke(Method.java:372)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:960)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)      原因:android.view.InflateException:二进制XML文件行#49:错误膨胀了类android.support.design.widget.FloatingActionButton         在android.view.LayoutInflater.createView(LayoutInflater.java:633)         在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)         在android.view.LayoutInflater.rInflate(LayoutInflater.java:806)         在android.view.LayoutInflater.inflate(LayoutInflater.java:504)         在android.view.LayoutInflater.inflate(LayoutInflater.java:414)         在android.view.LayoutInflater.inflate(LayoutInflater.java:365)         在android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)         在android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)         在com.example.pawan.madc.MainActivity.onCreate(MainActivity.java:26)         在android.app.Activity.performCreate(Activity.java:6100)

1 个答案:

答案 0 :(得分:0)

请尝试添加支持设计库,因为fab按钮是设计库组件。     

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'

您的活动主题也应该是适当的Theme.AppCompat主题。 FAB还需要colorAccent。确保将它们包含在styles.xml中。

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorAccent</item>
</style>