java.lang.NoClassDefFoundError: java/awt/Desktop in JDK 1.7
java.lang.NoClassDefFoundError: java/awt/Desktop in JDK 1.7
我正在尝试使用 Gmail API,但我遇到了这个 运行 时间异常:
java.lang.NoClassDefFoundError: java/awt/Desktop
它出现在这里(在最后一行):
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");
此代码位于 AsyncTask
的 doInBackground()
方法中。
我已经检查 Android Studio 配置为使用 JDK 1.7.
为什么会发生这种情况,我该如何解决?
Android不支持全部JDK类,只支持一个subset and java.awt
is not part of it. Therefore java.awt.Desktop
cannot be found. It seems like you're not using the right API at all. You should use Android Quickstart代替。
我正在尝试使用 Gmail API,但我遇到了这个 运行 时间异常:
java.lang.NoClassDefFoundError: java/awt/Desktop
它出现在这里(在最后一行):
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");
此代码位于 AsyncTask
的 doInBackground()
方法中。
我已经检查 Android Studio 配置为使用 JDK 1.7.
为什么会发生这种情况,我该如何解决?
Android不支持全部JDK类,只支持一个subset and java.awt
is not part of it. Therefore java.awt.Desktop
cannot be found. It seems like you're not using the right API at all. You should use Android Quickstart代替。