[英]java.lang.NoClassDefFoundError: java/awt/Desktop in JDK 1.7
I am trying to use the Gmail API and I encountered this run-time exception: 我正在尝试使用Gmail API,但遇到此运行时异常:
java.lang.NoClassDefFoundError: java/awt/Desktop
It occurs here (on the last line): 它发生在这里(在最后一行):
InputStream stream = ReadMail.class.getResourceAsStream("/client_secret.json");
Reader clientSecretReader = new InputStreamReader(stream);
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(ReadMail.JSON_FACTORY, clientSecretReader);
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(
ReadMail.HTTP_TRANSPORT, ReadMail.JSON_FACTORY, clientSecrets, ReadMail.SCOPES)
.setDataStoreFactory(ReadMail.DATA_STORE_FACTORY)
.setAccessType("offline")
.build();
AuthorizationCodeInstalledApp authCodeInstalledApp = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver());
Credential credential = authCodeInstalledApp.authorize("user");
This code is sitting in the doInBackground()
method of AsyncTask
. 这段代码位于
AsyncTask
的doInBackground()
方法中。
I have checked and Android Studio is configured to use JDK 1.7. 我已经检查过,并且Android Studio已配置为使用JDK 1.7。
Why does this happen and how can I fix it? 为什么会发生这种情况,我该如何解决?
Android does not support all JDK classes, only a subset and java.awt
is not part of it. Android不支持所有JDK类,只有一个子集,而
java.awt
不是其中的一部分。 Therefore java.awt.Desktop
cannot be found. 因此,找不到
java.awt.Desktop
。 It seems like you're not using the right API at all. 似乎您根本没有使用正确的API。 You should use Android Quickstart instead.
您应该改用Android快速入门 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.