Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

java.lang.ArrayIndexOutOfBoundsException: 0

How do II
I have trouble moving an array field to a String field. and get out of bounds
public static void InsertLetter_A_Cand_Email_t(
      
            String emailAddress,
            String strBdId,
            String strSsn) {
            int la_return = 0;      
            Statement stmt = null;
            Connection con = null;
            ResultSet rs = null;
            String sysDate = null;
            String[] sa_email = split(emailAddress, "@");
            //java.lang.ArrayIndexOutOfBoundsException: 0 below
            String str_akouser = sa_email[1];
}
Thank you in advance
0
coolgem
Asked:
coolgem
1 Solution
 
acharbonneauCommented:
Please list the function parameter values you used when the exception occurred.
It looks like emailAddress may not have contained the @ symbol.
0
 
coolgemAuthor Commented:
Hi acharbonneau,
If the field is null then there would not be a @ symbol.
However because it is an address such as firstname.lastname @xxx.zzz.mmm
other than a null it should specify as  firstname.lastname @xxx.zzz.mmm
0
 
esorfCommented:
Print out the emailAddress as a little debugging test.  I'm sure you'll see immediately that it does not contain the value you expect it to contain.

    System.out.println("Email: " + emailAddress);
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
introbertCommented:
As has been suggested, you may be evaluating an email address that doesn't contain a "@".  If this is the case, a try/catch loop like the one below may help you to handle this exception better.  Also, I didn't know what split method you were using, but I might suggest using the split method in the String class which I demonstrated below.

String[] sa_email = emailAddress.split("@");
try {
    String str_akouser = sa_email[1];
} catch (IndexOutOfBoundsException e){
    // do whatever you want to happen when the email address being evaluated
    // doesn't contain a "@"
}
0
 
esorfCommented:
Or better still

String[] sa_email = emailAddress.split("@");
if ( sa_email.length == 1 ) {
  // Missing @
}
else if ( sa_email.length > 2 ) {
  // 2 or more @
}
else {
  // Just one @,
}
0
 
coolgemAuthor Commented:
Thank you esorf for your help
0
 
esorfCommented:
My pleasure.  Thanks for the points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now