英文:
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 -->
专注分享java语言的经验与见解,让所有开发者获益!
评论