【问题标题】:why does importing swing gives me an error in kotlin为什么导入swing会在kotlin中给我一个错误
【发布时间】:2021-06-28 17:43:47
【问题描述】:

import javax.swing.* 显示未解决的导入引用我已尝试进行一些 google 搜索和 youtube 但没有结果也尝试搜索某些依赖项 build.gradle:-

`插件{ id 'com.android.application' id 'kotlin-android' }

机器人{ compileSdkVersion 30 buildToolsVersion "30.0.3"

defaultConfig {
    applicationId "com.example.example"
    minSdkVersion 18
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
packagingOptions {
    pickFirst 'androidsupportmultidexversion.txt'
}

buildTypes {
    release {
        minifyEnabled 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'
}
buildFeatures {
    viewBinding true
}

}

依赖{

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.intellij:forms_rt:7.0.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation platform('com.google.firebase:firebase-bom:28.0.1')
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-core:19.0.0'
implementation 'com.android.support:multidex:1.0.3'

}`

【问题讨论】:

  • 你为什么要在 Android 上使用 Swing?

标签: android kotlin


【解决方案1】:

您可以在 Android 中使用 Swing

这是因为Swing 是为Java SE 开发的,而Android 是基于Android 自己的Java 实现。由于两种 Java 实现不同,您不能在 Android 中使用 Swing

改为,请使用 Android 提供的 UI 组件来构建应用的 UI。 You can follow this guide to build a simple UI.

PS:如果您对这两种 Java 有何不同感到好奇,请you can read this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-14
    • 2013-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多