r - com.google.android.material.R 无法为 BottomNavigationView 解析符号“R”
问题描述
我在我的应用程序中使用了 BottomNavigationView,但我有一个问题:在 BottomNavigationView.java 中有 import com.google.android.material.R 并且 R 是红色的并且写着“无法解析符号 'R'”。我看到的话题帮不了我。
你会给我推荐什么?
依赖项:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example.yourspeakingclub"
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'src/main/java/Models', 'src/main/java/com/salendor/yourspeakingclub/models']
}
}
buildToolsVersion = '28.0.3'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.android.support:support-compat'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
implementation 'com.google.android.material:material:1.1.0-beta01'
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/navigation_container_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation_element"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_gravity="start"
android:background="?android:attr/windowBackground"
app:itemTextColor="#000000"
app:labelVisibilityMode="unlabeled"
app:itemIconTint="@color/colorBlack"
app:menu="@menu/bottom_menu" />
</FrameLayout>
此处提供了“R”问题所在的类定义:https ://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/bottomnavigation /底部导航视图.java
谢谢
解决方案
该错误应该通过 Alt+Enter 和添加正确的导入来解决。但我猜这个问题是在你已经构建并运行了至少一次项目之后突然出现的(因为它曾经发生在我身上)。这可能是因为您无法引用 XML 布局的元素。在这种情况下,请尝试:
构建 -> 清理项目
. 这解决了我的问题。希望它也会对您有所帮助:)
推荐阅读
- c# - 在 button1 上单击创建变量,在 button2 上单击使用在 button1 | 中创建的变量。C# WPF
- node.js - Axios - Cheerio 如何等待所有信息从服务器加载
- swift - 您如何根据用户输入发送通知?迅速
- symfony5 - 如何解决 Symfony 5.1.5 上的 Lexit JWT 401 错误“由于系统问题无法处理身份验证请求”
- javascript - 在服务器 jquery.min.js:2 POST https://company.co.in/Home/tbl 404 上出现错误(未找到)
- r - 变异数据框以检查两个数据框之间的数据是否重复
- javascript - JS:动态添加链接到某个类的所有元素
- typescript - 属性 'subscriptionClient' 是私有的,只能在类 'WebSocketLink'.ts(2341) 中访问
- reactjs - 如何在 ag 网格中添加动作列,其中每行都有编辑/删除按钮?
- php - 如果与前一个元素具有相同的键,则合并数组