我遇到了一些问题,当我在片段中定义参数时,参数的名称属性中的字母显示为红色,但我在顶部的XML文件中看到绿色的勾号,这意味着没有发现问题.我的Android工作室是长颈鹿版本.这个错误的消息是: "FirstName"不是标记"参数"的有效目标 我试着用其他词,但每次我都有这个错误.我编译了程序并在模拟器上运行,一切听起来都很好,程序运行正常.您可以在下图中看到此错误.我将我的Android工作室更新到了长颈鹿,以解决导航的存储库问题,现在在长颈鹿版本中,我遇到了这个问题.这似乎是Android Studio 的一个问题.

Build.gradle.kts(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
    }
    dependencies {
        val nav_version = "2.6.0"
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
    }
}

plugins {
    id("com.android.application") version "8.1.0" apply false
    id("org.jetbrains.kotlin.android") version "1.8.0" apply false
}

Build.gradle.kts(应用程序)

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    //id("androidx.navigation.safeargs")
    id("androidx.navigation.safeargs.kotlin")
}

android {
    namespace = "com.example.e12s02_navigationcomponent"
    compileSdk = 33

    defaultConfig {
        applicationId = "com.example.e12s02_navigationcomponent"
        minSdk = 24
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {

    implementation("androidx.core:core-ktx:1.10.1")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.9.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

    //Navigation Component
    implementation("androidx.navigation:navigation-fragment-ktx:2.6.0")
    implementation("androidx.navigation:navigation-ui-ktx:2.6.0")
}

Main_nav.xml

<?xml version="1.0" encoding="utf-8"?>
<navigation 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/main_nav_graph"
    app:startDestination="@id/firstFragment">

    <fragment
        android:id="@+id/firstFragment"
        android:name="com.example.e12s02_navigationcomponent.FirstFragment"
        android:label="fragment_first"
        tools:layout="@layout/fragment_first" >
        <action
            android:id="@+id/action_firstFragment_to_secondFragment"
            app:destination="@id/secondFragment" />
    </fragment>
    <fragment
        android:id="@+id/secondFragment"
        android:name="com.example.e12s02_navigationcomponent.SecondFragment"
        android:label="fragment_second"
        tools:layout="@layout/fragment_second" >
        <action
            android:id="@+id/action_secondFragment_to_firstFragment"
            app:destination="@id/firstFragment" />
        <argument
            android:name="firstName"
            app:argType="string" />
    </fragment>
</navigation>

enter image description here

我怎么才能解决这个问题?

推荐答案

这是Android Studio Giraffe中的一个错误.我下载并安装了Android Studio Flamingo,一切运行正常.

Android Studio Giraffe中的另一个错误是MotionLayout中的开始和结束布局不能正常工作.

Android相关问答推荐

房间打开创建回调java.nio.channels. OverlappingFilLockResponse

图像在Android Studio中显示,但不在设备中显示

如何将两个变量传递给Nav主机,然后将其传递给另一个屏幕?

在Jetpack Compose中的隐藏状态栏后面绘制

使用 Jetpack Compose 在 Android TV 上启用系统声音

如何在 Jetpack Compose 中处理水平滚动手势和变换手势

更改当前活动并返回后,Android webview 滚动不起作用

在 compose 中做可变状态堆栈

我可以从 Android 中的选定文本中获取周围的文本吗?

Jetpack Compose 如何使一个项目相对于另一个项目垂直居中

@Immutable 对数据类有什么好处?

在单元测试下断言协程未完成

从活动共享视图模型以使用 hilt 组合函数

单击过go 的文章时 NewsApp 崩溃

如何在 Jetpack Compose 中的 VisualTransformation 之后将光标保持在文本字段的末尾

操作系统会终止已启动的服务并调用Service.onDestroy吗?

Android全屏AlertDialog

我可以在不解密的情况下使用 JSch 获取加密的 SSH 私钥的类型或 fingerprint 吗?

我的自定义视图没有显示我应该如何修复它?

compose :为什么以记住启动的列表触发方式与快照不同