遇到“找不到主方法”错误,不确定原因。

huangapple 未分类评论44阅读模式
英文:

Getting a Main Method not found error and Not sure why

问题

import com.sendgrid.*;
import java.io.IOException;

public class EmailSender {

  public static void main(String[] args) throws IOException {

    Email from = new Email("#####@gmail.com");
    String subject = "Sending with SendGrid is Fun";
    Email to = new Email("$$$$$$@gmail.com");
    Content content = new Content("text/plain", "and easy to do anywhere, even with Java");
    Mail mail = new Mail(from, subject, to, content);

    SendGrid sg = new SendGrid("########");
    Request request = new Request();
    try {
      request.setMethod(Method.POST);
      request.setEndpoint("mail/send");
      request.setBody(mail.build());
      Response response = sg.api(request);
      System.out.println(response.getStatusCode());
      System.out.println(response.getBody());
      System.out.println(response.getHeaders());
    } catch (IOException ex) {
      throw ex;
    }
  }
}
英文:

Im integrating an email sending API and when trying to some java code I am getting "Main method not found in the file, please define the main method as: public static void main(String[] args)" although my code includes this.

Here is my code:

import com.sendgrid.*;
import java.io.IOException;


public class EmailSender {
 
  public static void main(String[] args) throws IOException {

    Email from = new Email("#####@gmail.com");
    String subject = "Sending with SendGrid is Fun";
    Email to = new Email("$$$$$$@gmail.com");
    Content content = new Content("text/plain", "and easy to do anywhere, even with Java");
    Mail mail = new Mail(from, subject, to, content);

    SendGrid sg = new SendGrid("########");
    Request request = new Request();
    try {
      request.setMethod(Method.POST);
      request.setEndpoint("mail/send");
      request.setBody(mail.build());
      Response response = sg.api(request);
      System.out.println(response.getStatusCode());
      System.out.println(response.getBody());
      System.out.println(response.getHeaders());
    } catch (IOException ex) {
      throw ex;
    }
  }
}

<!-- end snippet -->

huangapple
  • 本文由 发表于 2020年7月27日 07:11:56
  • 转载请务必保留本文链接:https://java.coder-hub.com/63106726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定