javax.* 无法导入到我的 Android 应用程序中? [英] javax.* cannot be imported in my Android app?

查看:59
本文介绍了javax.* 无法导入到我的 Android 应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 android 应用程序中导入一些 javax.* 类,但我在 Android Studio 中不断收到编译器错误.我使用的是 Ubuntu Linux 13.04.

I'm trying to import some javax.* classes in my android app, but I keep getting compiler errors inside Android Studio. I'm using Ubuntu Linux 13.04.

这是我的导入:

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
// Here are the imports I am having trouble with:
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.SourceDataLine;

当我尝试运行应用程序甚至编译活动 java 文件时,我收到以下错误:

And when I try to run the app or even compile the activity java file, I get these errors:

Gradle: error: package javax.sound.sampled does not exist
Gradle: error: package javax.sound.sampled does not exist
Gradle: error: package javax.sound.sampled does not exist

我就是想不通这个问题.任何帮助都会很棒!

I just can't figure out this problem. Any help would be awesome!

推荐答案

请注意,当您运行 Android 应用程序时:您不会在标准 JVM/JDK 上运行/编译它,您甚至不会执行 Java 字节码.Google 选择 Java 语言(或至少它的一个子集)作为进行 Android 开发的语言,但这只是语言.

Be aware that when you run an Android app: you don't run/compile it on a standard JVM/JDK, you don't even execute java bytecode. Google choose the java language (or at least a subset of it) as the language to do Android development, but it's only the language.

最后编译出来的java代码不是java字节码,而是dalvik字节码.(没有 .class 文件,而是 .dex 文件)

At the end the compiled java code is not java bytecode, but this is dalvik bytecode. (there is no .class files, but .dex files)

因此,在进行 Android 开发时:您不能使用完整的 JavaSE API:您只能使用 dalvik VM 支持的 API(可用 这里).

So, when doing Android development: you cannot use the full JavaSE API: you are limited to the API supported by the dalvik VM (available here).

(请注意,当您浏览此 API 时,请注意页面右上角的版本:在 API 级别 X 中添加.它会通知您支持该类的 Android-API 版本或方法)

(Note that when you browse this API beware of the version in the top right corner of the page : Added in API level X. It informs you about the Android-API version supporting that class or method)

这篇关于javax.* 无法导入到我的 Android 应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆