【问题标题】:App crashing android studio after moving project folder移动项目文件夹后应用程序崩溃 android studio
【发布时间】:2022-01-21 23:20:02
【问题描述】:

三周前,我决定将我的项目从 Mac 上的下载文件夹移动到我的桌面。移动项目后,我意识到我什至无法从项目中看到任何东西。因此,我决定将项目移回原来所在的下载文件夹中,并且我能够再次检查我的项目,但不幸的是我无法在手机上运行该项目,并且收到一条奇怪的错误消息,我我无法在互联网上找到解决方案。我将向您展示错误消息和活动的一些 XML 代码。

XML 代码:

<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="427dp"
        android:layout_height="82dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="413dp"
        android:layout_height="49dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0"
        app:navGraph="@navigation/mobile_navigation" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/home_view_message"
        android:textSize="12sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/nav_host_fragment"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.027" />

    <Spinner
        android:id="@+id/channel_spinner"
        android:layout_width="409dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@+id/nav_view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView6"
        app:layout_constraintVertical_bias="0.162" />

    <Button
        android:id="@+id/check_button"
        android:layout_width="157dp"
        android:layout_height="58dp"
        android:text="@string/home_button_text"
        app:layout_constraintBottom_toTopOf="@+id/nav_view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/channel_spinner"
        app:layout_constraintVertical_bias="0.418" />

</androidx.constraintlayout.widget.ConstraintLayout>

错误信息:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mychannels/com.example.mychannels.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3092)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6990)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
     Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
     Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
     Caused by: java.lang.reflect.InvocationTargetException

Build.gradle(应用级别):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.mychannels"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
    implementation 'androidx.navigation:navigation-fragment:2.0.0'
    implementation 'androidx.navigation:navigation-ui:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.preference:preference:1.1.0-alpha05'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

【问题讨论】:

  • 请发布您的build.gradle 应用级别
  • 你在这里遇到错误&lt;com.google.android.material.bottomnavigation.BottomNavigationView。你添加了BottomNavigationView库吗?
  • 检查你的背景颜色并检查this 一个也检查依赖关系。
  • 移除 android:background="?android:attr/windowBackground"

标签: java android xml android-studio


【解决方案1】:

文件 -> 使缓存无效/重新启动并尝试导入它。文件 -> 新建 -> 导入项目

【讨论】:

  • 使现金无效并重新启动项目对我也没有帮助。
【解决方案2】:

我认为您错过了在您的应用 gradle 文件中添加实现“com.google.android.material:material:1.1.0-alpha1”。只需在里面添加这个gradle 依赖项 { } 黑色并同步您的项目。现在,这个错误应该被删除并且项目将成功运行。

【讨论】:

  • 我尝试添加此实现,但我收到一条错误消息,提示我在添加此实现后尝试同步项目时无法解决此实现
  • 能否把错误贴在这里以便理解?
  • 这是我得到的错误:ERROR: Failed to resolve: com.google.android.material:material:1.1.0-alpha1 Show in Project Structure dialog Affected Modules: app
  • 只要确保你的项目级 gradle 文件中有 google() center 就像这个 repositories { google() jcenter() }
  • And also Try with File-> Sync project with Gradle file option from the top bar.
【解决方案3】:

在对我的问题进行一些搜索并尝试多次修复后,我重新尝试从 XML 代码中删除 android:background="?android:attr/windowBackground" 语句,应用程序打开并运行没有任何问题在我的手机上。我第一次打开此讨论时尝试这样做,但没有奏效。感谢您帮助我解决了我的问题!

【讨论】:

    【解决方案4】:

    我最近遇到了这个问题,在将项目移动到另一个文件夹后,唯一真正帮助我打开项目的是在启动 Android Studio 之前完全删除 build 文件夹(位于 app 文件夹内的文件夹) .在 Android Studio 4.1.3 / Windows 10 上测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      相关资源
      最近更新 更多