我嘗試使用Gmail API和我遇到的這個運行時異常:java.lang.NoClassDefFoundError:在JDK的Java/AWT /桌面1.7
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。
爲什麼會發生這種情況,我該如何解決?
這必須是一個類路徑問題,您不在運行時包含一些在編譯時可用的源代碼。 –
@MattClark他在Android上。 – chrylis
你必須包含堆棧跟蹤,而不僅僅是一行。我們需要知道觸發問題的類別負載。 – chrylis