kotlin的kmp编程中遇到Unresolved reference ‘java‘问题

解决办法

  • 打开 File → Project Structure → Project

  • 确保 Project SDK 是 与你的 jvmToolchain 保持一致

  • 如果没有,点击右上角 Add SDK 添加 JDK 路径

  • 同步Sync

  • 然后就正常了。

  • 复制代码
    package org.example.project
    
    import androidx.compose.animation.AnimatedVisibility
    import androidx.compose.foundation.Image
    import androidx.compose.foundation.layout.Column
    import androidx.compose.foundation.layout.fillMaxWidth
    import androidx.compose.material.Button
    import androidx.compose.material.MaterialTheme
    import androidx.compose.material.Text
    import androidx.compose.runtime.*
    import androidx.compose.ui.Alignment
    import androidx.compose.ui.Modifier
    import org.jetbrains.compose.resources.painterResource
    import org.jetbrains.compose.ui.tooling.preview.Preview
    import androidx.compose.foundation.layout.*
    import androidx.compose.material.Button
    import androidx.compose.material.Text
    import androidx.compose.runtime.*
    import androidx.compose.ui.unit.dp
    import androidx.compose.ui.window.Window
    import androidx.compose.ui.window.application
    import java.awt.FileDialog
    import java.awt.Frame
    
    @Composable
    @Preview
    fun App() {
        var selectedFiles by remember { mutableStateOf<List<String>>(emptyList()) }
        MaterialTheme {
            Column(
                modifier = androidx.compose.ui.Modifier.padding(16.dp),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Button(onClick = {
                    // 调用 AWT FileDialog 打开多文件选择器
                    val dialog = FileDialog(null as Frame?, "选择文件", FileDialog.LOAD)
                    dialog.isMultipleMode = true // 允许多选
                    dialog.isVisible = true
    
                    val files = dialog.files
                    if (files != null) {
                        selectedFiles = files.map { it.absolutePath }
                    }
                }) {
                    Text("选择多个文件")
                }
    
                Spacer(modifier = androidx.compose.ui.Modifier.height(16.dp))
    
                selectedFiles.forEach {
                    Text("✅ $it")
                }
            }
    
    
        }
    }
相关推荐
墨天梦16 小时前
D03_Compose列表与稳定身份
android·gitee·kotlin
萌新杰少17 小时前
Kuikly股票查看软件开发体验——SaiRen
android·kotlin·客户端
用户928172673901617 小时前
Android Compose版本的AI组件库来了。
android·kotlin
墨天梦1 天前
B19_SunnyWeather到阅读客户端
android·kotlin
墨天梦2 天前
B17_LifecycleLiveData与Flow
android·kotlin
熊猫钓鱼>_>3 天前
Kotlin Multiplatform for OpenHarmony 实战:为 Landscapist 实现图片加载适配
开发语言·kotlin·华为云·ai编程·harmonyos·鸿蒙·openharmony
熊猫钓鱼>_>3 天前
开源鸿蒙平台 KMP 三方库 KStore 适配全流程:从 ohosArm64 target 到真机文件持久化验证
人工智能·华为·开源·ai编程·harmonyos·openharmony·kmp
ZealSinger3 天前
Kotlin2.4迁移context parameters
kotlin·协程·迁移·kotlin2.4
墨天梦3 天前
B16_Material主题与可访问交互
android·kotlin·交互
alexhilton3 天前
模块化Jetpack Compose架构
android·kotlin·android jetpack