条码扫描器 zxing 在启动时崩溃

应用程序在启动时崩溃。试图只从官方中提取一段代码:zxing-sample

所以我的 activity_main.xml 代码来自示例,例如

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


<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent">

    <android.support.design.widget.AppBarLayout

        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

        android:layout_width="match_parent"

        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar

            android:id="@+id/toolbar"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"/>

    </android.support.design.widget.AppBarLayout>


    <LinearLayout

        android:orientation="vertical"

        android:layout_width="match_parent"

        android:layout_height="match_parent">

        <FrameLayout

            android:id="@+id/content_frame"

            android:layout_weight="1"

            android:layout_width="match_parent"

            android:layout_height="match_parent" />

        <LinearLayout

            android:orientation="horizontal"

            android:gravity="center"

            android:background="#222"

            android:layout_width="match_parent"

            android:layout_height="150dp">

            <Button

                android:text="Koristiti kameru"

                android:layout_weight="1"

                android:onClick="toggleFlash"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"/>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>


子衿沉夜
浏览 81回答 2
2回答

当年话下

在您的应用程序 Gradle 文件中,检查implementation 'com.android.support:design:28.0.0'您的dependencies

狐的传说

查看您的 Logcat,它显示了问题所在。&nbsp; &nbsp; java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.support.design.widget.AppBarLayout&nbsp; &nbsp; &nbsp;...&nbsp; &nbsp; &nbsp;Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.AppBarLayout" on path: DexPathList[[zip file "/data/app/com.example.myapplication-y9OZiywnTa-bCM9Op2luAw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-y9OZiywnTa-bCM9Op2luAw==/lib/arm, /system/lib, /vendor/lib]]所以,这意味着它无法启动您的活动MainAcitivty,因为它找不到类AppBarLayout。您可能缺少依赖项。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java