java


(javafx) I'm currently making an app which requires people to create an account, how can i make sure the texts fields aren't null?


I have some code written but it doesn't exactly work but it explains what I want it to do.
I think I've narrowed it down a little, it says I can't compare strings with == or !=, what is an alternative to this? I have changed my password fields to .equals() so they work properly, however I don't know an alternative for !=.
Controller class:
#FXML
private void handleCreateAccountContinue(ActionEvent event) throws IOException{
if(NewUsernameFieldC.getText()!=null && NewPasswordFieldC.getText()!=null && NewPasswordFieldC.getText()==NewPasswordConfFieldC.getText()
&& NewEmailFieldC.getText()!=null && NewSteamlinkFieldC.getText()!=null){
//ADD INFO TO DATABASE
System.out.println("correct input");
}
else{
System.out.println("incorrect input");
}
}
any ideas?
Thank you in advance!
You can´t check with null. You should check for empty String.
Also you should compare with equals not with "==" since String is an object. you will be comparing references and is not what you want. You want to compare text.
that´s why you should use equals.
NOTE: when you try to check if is not equals you just need to use the "!" at the beginning as I did it.
#FXML
private void handleCreateAccountContinue(ActionEvent event) throws IOException{
if(!NewUsernameFieldC.getText().isEmpty() && !NewPasswordFieldC.getText().isEmpty() && NewPasswordFieldC.getText().equals(NewPasswordConfFieldC.getText())
&& !NewEmailFieldC.getText().isEmpty() && !NewSteamlinkFieldC.getText().isEmpty()){
//ADD INFO TO DATABASE
System.out.println("correct input");
}
else{
System.out.println("incorrect input");
}
}
I believe the issue is that you're looking for blank text fields by comparing the input to null. You should instead be comparing the input to "" to see if nothing was entered. Hope it helps!
I've solved my issue, instead of doing this
Wrong code example:
#FXML
private void handleCreateAccountContinue(ActionEvent event) throws IOException{
if(NewUsernameFieldC.getText()!=null && NewPasswordFieldC.getText()!=null && NewPasswordFieldC.getText()==NewPasswordConfFieldC.getText()
&& NewEmailFieldC.getText()!=null && NewSteamlinkFieldC.getText()!=null){
//ADD INFO TO DATABASE
System.out.println("correct input");
}
else{
System.out.println("incorrect input");
}
}
You would do this:
#FXML
private void handleCreateAccountContinue(ActionEvent event) throws IOException{
if(!NewUsernameFieldC.getText().equals("") && !NewPasswordFieldC.getText().equals("") && NewPasswordFieldC.getText().equals(NewPasswordConfFieldC.getText())
&& !NewEmailFieldC.getText().equals("") && !NewSteamlinkFieldC.getText().equals("")){
//ADD INFO TO DATABASE
System.out.println("correct output");
}
else{
System.out.println("incorrect input");
}
}
I hope this helps someone!
I always check the length of the text
If(NewUsernameFieldC.getText().length > 0)
{
//the text field is not null
}

Related Links

EnableWebMvc throws ServletException: Could not resolve view with name
Locking some Excel Cells/Rows with POI others editable
Testing simple multithread code using EasyMock but got strange result
Spring JDBC Template with BoneCP Connection Pooling Configuration
is there any way to put for loop inside if condition statement as a short cut? [duplicate]
Jackson unable to map JSON to an Object containing a Map
Unable to scroll and click, as element is not visible in selenium with native android mobile application
Forcing inclussion of a jar using maven assembly plugin with jar-with-dependencies
getStringArrayExtra() returns null
Download (update) file from URL in Android. File's name is changing
Android restart service correctly after app is closed
Connecting android app with Wordpress site
How to upload file via REST service using RestTemplate in Java Spring MVC?
Docker: what are negative impacts of running container with memory limit enabled and memory overcommit disabled?
Hadoop singleton pattern uasge
Unable to load javacv and googlecode in openCV Project

Categories

HOME
vim
ionic-framework
deployment
pypi
urbancode
c#-4.0
pycharm
plone
routes
jsp-tags
microservices
v8
survey
umd
retrofit
mouse
podio
slurm
slick-slider
apache-cayenne
ibm-odm
decomposition
quartz-scheduler
systemc
seaborn
aurigma
database-replication
contextmenu
zapier
cx-freeze
clickonce
opencover
angular2-aot
status
msys2
libuv
instant-messaging
media-queries
javascriptcore
gtrendsr
http-get
webtest
asset-pipeline
gammu
google-api-nodejs-client
vapor
streamreader
bootstrapper
core-plot
wptoolkit
pango
git-diff
recursive-datastructures
forever
tactic
libusb-win32
nsarray
lync-client-sdk
mediaelement
google-cdn
spring-android
infix-notation
android-textview
slicknav
impresspages
oauth2client
python-3.2
drawbitmap
event-bubbling
remobjects
key-management
gadt
codeigniter-routing
rdl
has-many-through
typeof
mysql-error-1062
kgdb
jboss-weld
uv-mapping
xsockets.net
coverflow
jplaton
shellexecute
qt-faststart
sabredav
wsdl-2.0
cisco-jtapi
chrono
enter
amazon-appstore
deobfuscation
xtype
self-extracting
recent-documents
locate
fixed-width
firefox4

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App