【问题标题】:My app crash when use also once <android.support.design.widget我的应用程序在使用时也崩溃了一次 <android.support.design.widget
【发布时间】:2015-10-13 20:43:22
【问题描述】:

您好,我创建了示例项目但崩溃了。

我使用 kitkat 运行设备,但我的应用程序崩溃并且只显示以下消息 异常错误为什么?我使用 android studio lastversione

my build.grade 添加支持 22 和 appcompat

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.android.xxx"
        minSdkVersion 19
        targetSdkVersion 19
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}


dependencies {
    //compile 'com.android.support:appcompat-v7:22.0.0'
    //compile 'com.github.shell-software:fab:1.0.5'
    compile 'com.android.support:support-v4:+'
    compile 'com.android.support:appcompat-v7:22.0.0'

    compile 'com.android.support:cardview-v7:22.0.0'
    compile 'com.android.support:recyclerview-v7:22.0.0'

    compile 'com.android.support:design:22.2.0'

    compile 'com.google.code.gson:gson:2.3'
}

我的测试活动是从 android studio 创建的空白活动

我的测试活动

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.android.xxx.TestActivity">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_drawer"
        android:layout_gravity="bottom|end" />

</RelativeLayout>

更新

我找到了最佳配置

这在设备和模拟器上编译和运行,我的布局

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        >
        <include
            android:id="@+id/toolbar"
            layout="@layout/tool_bar"
        />
        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="401dp">

        </FrameLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_delete_black"
            android:layout_gravity="start|left" />



    </LinearLayout>



    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        app:headerLayout="@layout/header"
        app:menu="@menu/drawer"
        />
</android.support.v4.widget.DrawerLayout>

我的脚本

apply plugin: 'com.android.application'

android {
//    compileSdkVersion 22
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.android4dev.navigationview"
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
//    compile 'com.android.support:appcompat-v7:22.2.0'
//    compile 'com.android.support:design:22.2.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'

    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'

}

【问题讨论】:

    标签: android android-studio crash android-widget android-support-design


    【解决方案1】:

    您的构建工具和 sdk 版本不匹配。

    将您的构建工具版本更改为:

    buildToolsVersion '22.0.1'
    

    【讨论】:

      【解决方案2】:

      您的构建工具和库版本似乎很旧。当前版本是23.0.1 转到您的 sdk 管理和更新构建工具和支持库。

      更新工具后,更改您的 Gradle 文件以使用最新的构建工具和支持库,即23.0.1

      apply plugin: 'com.android.application'
      
      android {
          compileSdkVersion 23
          buildToolsVersion "23.0.1"
      
          defaultConfig {
              applicationId "com.android.xxx"
              minSdkVersion 19
              targetSdkVersion 23
          }
      
          buildTypes {
              release {
                  minifyEnabled false
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
              }
          }
      }
      
      
      dependencies {
          compile 'com.android.support:support-v4:23.0.1'
          compile 'com.android.support:appcompat-v7:23.0.1'
      
          compile 'com.android.support:cardview-v7:23.0.1'
          compile 'com.android.support:recyclerview-v7:23.0.1'
      
          compile 'com.android.support:design:23.0.1'
      
          compile 'com.google.code.gson:gson:2.3'
      }
      

      【讨论】:

      • support-v4 也应该有 23.0.1 作为版本,而不是通配符。
      • logcat 的主要行是: Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class android.support.design.widget.FloatingActionButton
      • @BruceStackOverFlow 是的,因为它无法在正确的库中找到 FloatingActionButton。您必须更新您的库以使用最新的正确版本。
      • 好的,我已经按照您的指示修改了版本...但不起作用...升级库??
      • update... 我修改了脚本:
        compileSdkVersion 23 buildToolsVersion "23.0.1" minSdkVersion 19 targetSdkVersion 19 ... compile 'com.android.support:support-v4:23.0. 1' 编译'com.android.support:appcompat-v7:23.0.1' 编译'com.android.support:cardview-v7:23.0.1' 编译'com.android.support:recyclerview-v7:23.0.1' compile 'com.android.support:design:23.0.1' compile 'com.google.code.gson:gson:2.3' compile at run on emulator and real device show this exception
      【解决方案3】:

      @Sharj

      带有输出的构建

      D:\Users\robi\StudioProjects\QuandoArrivo\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.1\res\values-v23\values-v23.xml
      Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
      Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.
      Error:Execution failed for task ':app:processDebugResources'.
      

      【讨论】:

      • 我从 support.design 中找到了使用 FloatingActionButton 和 Width 的项目。在模拟器和设备上运行。检查代码并找出问题所在。然后查看结果。其他提示总是在这里...link git-hub project
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2020-01-23
      • 2018-04-03
      相关资源
      最近更新 更多