#uhhh idk what title give here

34 messages ยท Page 1 of 1 (latest)

unreal sleet
#

Im making a project myself; so i got to this point. I need to check if a field its blank or null, but this doesnt work

long stirrupBOT
#

โŒ› This post has been reserved for your question.

Hey @unreal sleet! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

vale meadow
#

Use String#isBlank:

if (cbCursoAcademico.getSelectedItem() == null || cbCursoAcademico.getSelectedItem().isBlank()) {
    // ...
}

also, recommendations:

  1. I recommend not using string concatenation for
fila[0] = "" + c.getId();
fila[1] = "" + c.getCodigo();
// ...

instead, if those are integers and not strings, use

fila[0] = String.valueOf(c.getId());
fila[1] = String.valueOf(c.getCodigo());
// ...
  1. I recommend you cache the logger as a static variable:
private static final Logger = Logger.getLogger(jfrAlumnca.class)
unreal sleet
#

the debugger tell me that cbCursoAcademico.getSelectedItem = (java.lang.String)""
my condition its: if cbCursoAcademico.getSelectedItem()==null || cbCursoAcademico.getSelectedItem().equals("")

#

so idk why the program don't enter into that if

#

i will try the is blank

vale meadow
#

using String#isBlank is just good practice

unreal sleet
#

.isBlank its for java too? seems to dont suggest me it

vale meadow
#

what version of java are you using?

#

also, try slapping a log statement right before the if statement:

logger.log(Level.INFO, "Here is the string: '" + cbCursoAcademico.getSelectedItem() + "'");
unreal sleet
#

i have jdk 20

#

i got this... but idk why its false ๐Ÿ˜ฆ

vale meadow
#

never use == on a String

#

use .isBlank()

unreal sleet
#

yah i got that from .equals

#

the blank doesnt works also)

unreal sleet
#

ooh yah i have the blank thingie

vale meadow
unreal sleet
#

i was putting it bad xD

#

yessshhh the isblank works!!!

vale meadow
# vale meadow https://www.baeldung.com/java-compare-strings#comparison-op

Using the โ€œ==โ€ operator for comparing text values is one of the most common mistakes Java beginners make. This is incorrect because โ€œ==โ€ only checks the referential equality of two Strings, meaning if they reference the same object or not.

Let's see an example of this behavior:

String string1 = "using comparison operator";
String string2 = "using comparison operator";
String string3 = new String("using comparison operator");
 
assertThat(string1 == string2).isTrue();
assertThat(string1 == string3).isFalse();

In the example above, the first assertion is true because the two variables point to the same String literal.

On the other hand, the second assertion is false because string1 is created with a literal and string3 is created using the new operator โ€“ therefore they reference different objects.

unreal sleet
#

yah == comparing string gives false

#

cz its another class

#

but i was just testing all i knew to see if any works x.x

#

the equals check the "value"

#

so gives true

#

but this time was blank, didnt knew that isblank were a thing

#

thank u!!

long stirrupBOT
# unreal sleet thank u!!

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.