java - 为什么Android studio上找不到小程序?

标签 java android android-studio applet

我正在尝试在 android studio 中制作一个小程序,该小程序过去可以在不同计算机上的先前安装上运行。现在,虽然我在 import java.applet.Applet; 上遇到错误,说 无法解析符号 Applet。当我查看项目设置时,它指向 android studio 附带的 JRE8,所以我想这可能是因为它使用 jre 而不是 jdk,并安装了 openjdk8 并指出了这一点,但仍然没有运气。我还更改了 java_home 以指向这个新的 openjdk8,但是重新启动 android studio 时 java_home 仍然指向它自己的 jre。我正在使用 ubuntu linux。

感谢任何帮助

谢谢

Temp.java

package com.example.myapplication;

import java.applet.Applet;

public class Temp extends Applet {
}

项目build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

模块构建.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        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'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

最佳答案

Android Studio 主要用于创建 Android 应用。 Android 不支持小程序(据我所知,出于安全原因,几乎没有什么支持小程序)。

您在 Android Studio 中创建了一个 Android 项目。 Android 项目针对 Android SDK 而不是 JDK 进行编译,并且 Android SDK 不支持小程序(或 JDK 中的许多其他内容)。

如果您希望在 Android Studio 中构建 Java 小程序,您将需要:

  • 创建 Android Studio 项目
  • 向该项目添加 Java 库模块(从主菜单中选择"file">“新建”>“新建模块...”)
  • 在该库模块中开发您的小程序

使用其他 IDE(例如 IntelliJ IDEA)或不使用小程序可能会更好。

关于java - 为什么Android studio上找不到小程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59339988/

相关文章:

java - spring-data-mongodb:如何通过传递随机属性及其值来查找文档

android - 旧版 api 8 的文本按钮文本全部大写

android - android studio 3.3中的 "Include C++ support"选项在哪里?

android - 无法解析模块中的符号 'R'

android - 更新 Android SDK platform-tools 24 "Could not find method apt()"为什么?

java - 使用其他类中的公共(public)静态 HashTable 的同步方法。我怎样才能使这个方法线程安全?

java - 在 SmsServlet 文件中获取 NullPointerException : I am trying read value defined in jsp file SendSms. jsp

java - Stormpath idSite 环境身份验证问题

java - 从 apache 网站导入库

android - 无法在 Android 上使用 AES 密码读取加密视频