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

Why the last line of my code executes more then one time?
ArrayAdapter and retrofit 2.0
Selecting a date using custom calenderview
Securing a class file in Android Project
caesercipher( unable to work if method has to cycle through alphabets)
Need to put semicolon at the end of last line
Microsoft JDBC driver URL with Kerberos Authentication and ServerSpn
matlab java class gives nullpointer exception
Java writing/editing a properties file
WorldWind support for right click context menu
Unsupported major.minor version 52.0 Servlets
LineChart creation error with MPAndroid Chart, unable to start activity
Does DisplayTag PaginatedList work with external sorting?
Encoding and Decoding bin file
How to make my own List<T> implementation sortable?
RxJava infinite retry with new observable

Categories

HOME
google-chrome-extension
tizen
plot
platform-builder
kalman-filter
spring-cloud-stream
react-redux
cmd
graphql
survey
google-project-tango
convolution
networkx
django-imagekit
medical
circular-dependency
gz
size
visual-studio-2005
visual-studio-cordova
dosgi
database-replication
beyondcompare
zapier
cx-freeze
java-3d
functional-testing
arabic
csrf-protection
bootstrap-tour
blazemeter
emgucv
h2db
greendao
opentype
jspm
facebook-apps
jaxb2
quote
stringtemplate
restlet
serverside-rendering
libvpx
objectlistview
http-live-streaming
node-gyp
acoustics
convertapi
wptoolkit
menuitem
apache-fop
revapi
prolog-setof
worksheet
ionicons
datastax-startup
qtwebview
spring-mongodb
dwscript
word-vba-mac
infix-notation
mikroc
trash
google-web-starter-kit
lttng
markojs
skype4py
sdf
map-projections
arcanist
myo
generic-programming
ami
unity5.2.3
sonarqube5.1.2
nsmutabledictionary
block-device
dd
file-copying
rdtsc
rdl
xojo
comexception
viadeo
intentservice
mysqltuner
spring-io
flash-builder4.5
html4
pushbackinputstream
isnullorempty
quickdialog
coderush
ocx
nsmanagedobject
coercion
xmlspy
inotifycollectionchanged
pyinotify
radcombobox
h.323
dentrix
mozilla-prism
preference
castle-monorail
ncqrs
xetex
premature-optimization
noscript
thread-local-storage
signal-handling
windows-live-messenger

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App