使用javax。*不能在我的Andr​​oid应用程序导入?在我、应用程序、javax、oid

2023-09-12 00:57:42 作者:一壶流年

我想进口一些的javax。* 班在我的Andr​​oid应用程序,但我不断收到内部的Andr​​oid 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字节code。谷歌选择了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 code不是Java字节code,但这是Dalvik的字节code。 (没有.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虚拟机(可用的这里)。

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)