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

解决办法

  • 打开 FileProject StructureProject

  • 确保 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")
                }
            }
    
    
        }
    }
相关推荐
梓仁沐白1 小时前
【Kotlin】注解&反射&扩展
开发语言·python·kotlin
移动开发者1号9 小时前
Jetpack Compose瀑布流实现方案
android·kotlin
移动开发者1号9 小时前
Android LinearLayout、FrameLayout、RelativeLayout、ConstraintLayout大混战
android·kotlin
移动开发者1号9 小时前
ListView与RecyclerView区别总结
android·kotlin
移动开发者1号9 小时前
OkHttp 3.0源码解析:从设计理念到核心实现
android·kotlin
MZWeiei18 小时前
KMP 算法中 next 数组的构建函数 get_next
算法·kmp
casual_clover1 天前
Android 之 kotlin语言学习笔记三(Kotlin-Java 互操作)
android·java·kotlin
梓仁沐白1 天前
【Kotlin】数字&字符串&数组&集合
android·开发语言·kotlin
Dola_Pan1 天前
Android四大组件通讯指南:Kotlin版组件茶话会
android·开发语言·kotlin
移动开发者1号1 天前
应用启动性能优化与黑白屏处理方案
android·kotlin