Currently String.isEmpty() is not included in our base JRE.   You can see
the supported API in the javadocs:
https://www.codenameone.com/javadoc/java/lang/String.html

Missing string methods generally have an alternative.  In this case use
 username.getText().trim().length() == 0.

Some other utility methods can be found in the StringUtil class.
https://www.codenameone.com/javadoc/com/codename1/util/StringUtil.html


Steve

On Mon, Apr 3, 2017 at 1:46 AM, TheHyng <[email protected]>
wrote:

> If you are experiencing an issue please mention the full platform your
> issue applies to:
> IDE: NetBeans/Eclipse/IDEA
> Desktop OS
> Simulator
> Device
>
> NetBeans platform
>
> Hi guys, so I have a problem in my code, so I'm starting some kind of
> login form and I wan't to check if the textfield is empty or not before
> adding the values to the variables but when I added the new if :
>
> if (username.getText()==null || username.getText().trim().isEmpty())
>
> I got this build output:
>
> ant -f "G:\\Codename One\\CodenameOne" -Dnb.internal.action.name=rebuild
> clean jar
> No GUI Entries available
> init:
> deps-clean:
> Updating property file: G:\Codename One\CodenameOne\build\built-
> clean.properties
> Deleting directory G:\Codename One\CodenameOne\build
> refresh-libs:
> Deleting directory G:\Codename One\CodenameOne\lib\impl
> clean:
> No GUI Entries available
> init:
> deps-jar:
> Created dir: G:\Codename One\CodenameOne\build
> Updating property file: G:\Codename One\CodenameOne\build\built-
> jar.properties
> Created dir: G:\Codename One\CodenameOne\build\classes
> Compile is forcing compliance to the supported API's/features for maximum
> device compatibility. This allows smaller
>         code size and wider device support
> Created dir: G:\Codename One\CodenameOne\build\tmp
> Compiling 1 source file to G:\Codename One\CodenameOne\build\tmp
> G:\Codename One\CodenameOne\src\com\mycompany\myapp\mainclassZ.java:103:
> error: cannot find symbol
>                 if (username.getText()==null || username.getText().trim().
> isEmpty()){
>   symbol:   method isEmpty()
>   location: class String
> 1 error
> G:\Codename One\CodenameOne\build.xml:57: Compile failed; see the compiler
> error output for details.
> BUILD FAILED (total time: 2 seconds)
>
> So this is the code of my login form:
>
> Form login = new Form("Login");
>         setBackCommand(login);
>         TextField username = new TextField("","Username", 20,
> TextField.INITIAL_CAPS_WORD);
>         TextField password = new TextField("", "Password", 20,
> TextField.PASSWORD);
>         Button userlogin = new Button("Login");
>
>         userlogin.addActionListener(new ActionListener(){
>             @Override
>             public void actionPerformed(ActionEvent evt){
>                 if (logged==false){
>                 if (username.getText()==null || username.getText().trim().
> isEmpty()){
>                     Dialog.show("Warning!", "Please, fill all the
> fields!", "Ok","Cancel");
>                 }
>                 else{
>                     //How do I add the textfield content to the variables
> user1 and pass1?
>                     Dialog.show("Logged in!", "Log in successful! Welcome
> "+user1+"!", "Ok", "Close Dialog");
>                     logged=true;
>                     user1=username.getText();
>                     pass1=password.getText();
>                 }
>                 }
>                 else
>                     Dialog.show("Warning!", "You are already logged into
> an account please log out first!","Ok", "Cancel");
>             }
>         });
>
> --
> You received this message because you are subscribed to the Google Groups
> "CodenameOne Discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> Visit this group at https://groups.google.com/
> group/codenameone-discussions.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/codenameone-discussions/94bb2e3f-68d2-4a33-ae70-
> b904923633fe%40googlegroups.com
> <https://groups.google.com/d/msgid/codenameone-discussions/94bb2e3f-68d2-4a33-ae70-b904923633fe%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Steve Hannah
Software Developer
Codename One
http://www.codenameone.com

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/CAGOYrKXWfh184DsHpykwgLiViKGNKCdWycHzGudi9uz0D7_ECw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to