1

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;
    }
  }
}
Dev Ghai
  • 21
  • 1
  • Which Debug configuration you are using? "mainClass" decides which file it will run, ${file} means the currently opened file. – Steven-MSFT Jul 29 '20 at 01:35
  • Most likely you are not *actually* running that class. Because the `main` method you have shown us there is a valid entry point method. – Stephen C Jul 15 '21 at 07:59
  • See https://stackoverflow.com/questions/5407250 for what this error message *usually* means. – Stephen C Jul 15 '21 at 08:09

0 Answers0