Java Question FATAL EXCEPTION: main (java.lang.VerifyError: esdaSO.Android.Lib.SendTheMail)

Amalkotey

Active Member
Licensed User
Hello,

I 've written a library, which is transmitted directly from my program B4A an email. Under the Eclipse class works fine when I imagine an instance in the main and execution. The compilation is without error. My B4A test programs can be found all members and can be compiled without error. On my device, will test the program but dropped out of the above error message.

Bottom of the log is the following error

B4X:
Start proc esdaSO.LibraryDemo.SendTheMail for activity esdaSO.LibraryDemo.SendTheMail/.main: pid=28464 uid=10144 gids={1015}
FATAL EXCEPTION: main
java.lang.VerifyError: esdaSO.Android.Lib.SendTheMail
   at esdaSO.LibraryDemo.SendTheMail.main._globals(main.java:304)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
   at esdaSO.LibraryDemo.SendTheMail.main.initializeGlobals(main.java:201)
   at esdaSO.LibraryDemo.SendTheMail.main.afterFirstLayout(main.java:81)
   at esdaSO.LibraryDemo.SendTheMail.main.access$100(main.java:16)
   at esdaSO.LibraryDemo.SendTheMail.main$WaitForLayout.run(main.java:72)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:4627)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
   at dalvik.system.NativeStart.main(Native Method)
  Force finishing activity esdaSO.LibraryDemo.SendTheMail/.main

I could isolate the error to find the following method, but not make the mistake!

B4X:
private void SendMailWithoutAttachments() {
    Authenticator authenticator = null;
    try {
        lastError = "";

        //Set the host smtp address
   Properties props = new Properties();
   props.put("mail.smtp.host", SMTPHost);

   if (auth == true)
       props.put("mail.smtp.auth", "true");
   else
       props.put("mail.smtp.auth", "false");

   props.put("mail.transport.protocol", "smtp");
   props.put("mail.smtp.port", Port.toString());

   if (auth == true) {
       authenticator = new SMTPAuthenticator();
   }
   Session session = Session.getInstance(props, authenticator);

   // create a message
   Message msg = new MimeMessage(session);

   // set the from and to address
   InternetAddress addressFrom = new InternetAddress(SenderMailAdress);
   msg.setFrom(addressFrom);

   // Set the Receiver mail adresses
   InternetAddress[] addressTo = new InternetAddress[To.getSize()];
   for (int i = 0; i < To.getSize(); i++) {
       addressTo[i] = new InternetAddress((String) To.Get(i));
   }
   msg.setRecipients(MimeMessage.RecipientType.TO, addressTo);

   // Setting the Subject and Content Type
   msg.setSubject(Subject);
   if (htmlMail == true)
       msg.setContent(MsgText, CONTENT_HTML);
   else
       msg.setContent(MsgText, CONTENT_TEXT);
         }
   Transport.send(msg);
    } catch (MessagingException mex) {
         mex.printStackTrace();
         lastError = "Method: sendMail" + crLF + mex.toString();
         Exception ex = null;
         if ((ex = mex.getNextException()) != null) {
            ex.printStackTrace();
            lastError = "Method: sendMail" + crLF + ex.toString();
         }
    }
}

The authentication is done with the following code.

B4X:
   public class SMTPAuthenticator extends javax.mail.Authenticator {
      private PasswordAuthentication authentication;

      public SMTPAuthenticator() {
         authentication = new PasswordAuthentication(UserName, Password);
      }
      
      protected PasswordAuthentication getPasswordAuthentication() {
         return authentication;
      }
   }

The error caused by my library. I think this is a failed authentication. Deck is right I oer my fault somewhere else? Without your help I think the mistake before. Thanks for your help in advance.

best regards
Amalkotey
 
Last edited:

Amalkotey

Active Member
Licensed User
Trigger error found

Information:

The fault lay in the Catch block. The error defination "MessagingException" was involved with

B4X:
import javax.mail.MessagingException;

and appears to be incorrect. I have now changed to general error handling

B4X:
try {
    if (Attachments.getSize() == 0)
        SendMailWithoutAttachments();   
    else
        SendMailWithAttachments();
} catch (Exception e)
      e.printStackTrace();
      lastError = "Method: sendMail" + crLF + e.toString();
}

In any case, started with the authoritarian code program. Thus the problem solved. I hope that other developers to troubleshoot this information is helpful and can fix it so.

regards
Amalkotey
 

Erel

Administrator
Staff member
Licensed User
When you say that it runs fine in Eclipse, you are actually running it on the desktop not on Android device, right? Android doesn't support all of the desktop Java libraries.

Why not use Net library: New Net library - Android FTP, SMTP and POP3
It supports SMTP and allows you to send files with attachments directly from your application.
 

Amalkotey

Active Member
Licensed User
@Erel:
Thank you for your help. I did not have the Net - Library installed. I have, although looking ih several times a day after the new posts, the post "New Net library - Android FTP, SMTP and POP3" not found. Which I would now saves a lot of work.

Since I am in future IT projects using Java and want to settle with SAP ABAP (I 'm from 20.09.2011 in a SAP ABAP training), are such problems for the learning effect is not bad. The error does not now when I start the B4A program, but when I SendTheMail method in B4A call this method though.

I will now use the Net Library, but find the error, I daimit also have a learning effect. Although I am certified as OCPJP, but only actually working since early June 2011 with Java when I passed my certification percentage at 81. I think I just missing the Java experience. In the past, I was the Delphi Professional for Windows.

regards
Amalkotey
 
Last edited:
Top