gpt4 book ai didi

Java GMail api - java.lang.VerifyError : Cannot inherit from final class

转载 作者:行者123 更新时间:2023-12-02 02:31:36 35 4
gpt4 key购买 nike

我正在使用 glassfish 服务器 4.1 和 java JDK 1.8。我使用maven来构建和部署。

我制作了一个表单,触发 Controller 使用 gmail api 发送电子邮件。

触发 Controller 的表单:

<form method="post" action=GmailController>
<td>Test API gmail</td>
<td><input name="email" value="${requestScope.get("email")}" /></td>
<td><input type="submit" value="Send email" /></td>
</form>

Controller “GmailController”:

@WebServlet("/GmailController")
public class GmailController extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String email = request.getParameter("email");

try {
sendAnEmail("email_body", email, email); //custom method that uses gmail API
} catch (Exception e) {
e.printStackTrace();
}
}

}

调用GMail API函数的sendAnEmail方法:

public static void sendAnEmail(String body, String from, String to) throws Exception {
Gmail service = getGmailService();
MimeMessage msg = createEmail(to, from, "Area", body);
sendMessage(service, "email@example.com", msg);

}

当我提交触发 Controller 的表单时,我收到 HTTP 500 错误并且 glassfish 显示:

java.lang.VerifyError: Cannot inherit from final class

当我在 java glassfish Web 应用程序之外测试 GMail API 时,它通过在 java main 中调用 sendAnEmail 正常工作。

我不明白是什么原因导致此错误,因为我的类不继承自除 HttpServlet 之外的任何其他类。

当我注释 sendAnEmail() 调用时,没有错误,因此该错误一定不是由于 HttpServlet 继承所致。

什么可能导致此错误?我如何调试或获取有关它的更多信息?

在 server.log 中我没有得到更多信息,它显示相同的错误并告诉线程已停止。

经过一些测试,另一台计算机和操作系统上的完全相同的代码给出:

java.lang.NoSuchMethodError: com.google.api.client.util.ClassInfo.getFieldInfos()Ljava/util/Collection;

相反。

google-api-services-oauth2、google-api-services-gmail 和 google-api-client 均为版本 1.23.0。

最佳答案

错误:java.lang.VerifyError:无法从最终类继承

基于此thread ,您已经成功创建了一个扩展父类(super class)的类,其中父类(super class)已声明为 final

The most likely cause is that you have a conflict between your build classpath and your launch classpath. In other words, you are compiling your subclass against a version of the superclass that is not final, and then running against a version that is final. The verifier is saying (correctly) that this is wrong.

错误:java.lang.NoSuchMethodError:com.google.api.client.util.ClassInfo.getFieldInfos()Ljava/util/Collection;

基于此forum ,您的代码(间接)调用了不存在的方法。检查您在类路径中使用的依赖项。

希望这有帮助!

关于Java GMail api - java.lang.VerifyError : Cannot inherit from final class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47005000/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com