Question

I'm building an application in Codenameone (Java) and need a quick email check with regex.
But now for some reason whenever I build my app I get the error that the java.util.regex package does not exist.
Netbeans gives no errors when compiling and I can access the sourcecode from all the classes in java.util.regex but for some reason netbeans can not find it when building.

I did some searching on the web but could not find anything of use.
I use Netbeans 7.4 and JDK 7 (JRE 1.7.0_51)

This is the code for the mail check:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

protected boolean checkMail(String email) {
    String EMAIL_PATTERN
            = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
            + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

    Pattern pattern = Pattern.compile(EMAIL_PATTERN);
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}

This is the error i get:

F:\Pantera\Documents\NetBeansProjects\TherapieApp\src\be\pantera\TherapieApp\RegisterPage.java:25: error: package java.util.regex does not exist import java.util.regex.Matcher;
F:\Pantera\Documents\NetBeansProjects\TherapieApp\src\be\pantera\TherapieApp\RegisterPage.java:26: error: package java.util.regex does not exist import java.util.regex.Pattern;

--EDIT-- Seems this problem is related to codenameone so i changed the title. Thank you to those who answered before the edit. I didn't think the problem could be related to Codenameone, my apologies.

Was it helpful?

Solution

Codename One doesn't support that package nor many other packages in the Java SE stack. Java SE is too big for mobile, our current hello world for iOS is 3mb and if we supported the full Java SE it would be around 18mb. The same is true for Windows Phone, RIM etc.

There are several solutions including a port of a 3rd party regex cn1lib.

You can see the classes supported by Codename One in the JavaDocs: https://codenameone.googlecode.com/svn/trunk/CodenameOne/javadoc/index.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top