• Hello Members, This forums is for DV lottery visas only. For other immigration related questions, please go to our forums home page, find the related forum and post it there.

Anyone do Java coding???

Britsimon

Super Moderator
Trying to figure out some VERY basic java code for the CEAC data

There are some new possible status codes (there were ISSUED, REFUSED and so on) there are now "at NVC" and "in Transit". When I see either of those I want to not do some extra logic.

I am getting myself confused with the OR logic.


So - this works (If "at NVC" was the only extra status):

if (
!status.ownText().toString().toUpperCase().contains("NVC")
)
{



But this does not work:
if (
!status.ownText().toString().toUpperCase().contains("NVC")
||
!status.ownText().toString().toUpperCase().contains("TRANSIT")
)
{

When I run that I get a NullPointerException.

Anyone able to correct my OR logic. The test should look for either value, not both.
 
You're right. It should either both work, or both not, unless somehow one of .ownText() or .toString() returns different things when called twice, or one of them has side effects where it causes the next time you call it it fails, or something (from the sound of the name "ownText", it doesn't sound like it should do that, but who knows?). Anyway, do you have a stack trace that shows where the exception is happening? You can separate out the chain of calls so that each intermediate value is assigned to a temporary variable, and then test each one for null, to see which one is null.
 
You're right. It should either both work, or both not, unless somehow one of .ownText() or .toString() returns different things when called twice, or one of them has side effects where it causes the next time you call it it fails, or something (from the sound of the name "ownText", it doesn't sound like it should do that, but who knows?). Anyway, do you have a stack trace that shows where the exception is happening? You can separate out the chain of calls so that each intermediate value is assigned to a temporary variable, and then test each one for null, to see which one is null.


Yeah - they were working against each other. I did it another way (two tests, set a boolean then test the boolean) and that seems to be working.
 
Yeah - they were working against each other. I did it another way (two tests, set a boolean then test the boolean) and that seems to be working.

Hi Britsimon

Dont use OR (||), Use AND (&&).

Explanation:-

Since you are using not in front, one condition should be failed to execute inside coding. If you use OR always one condition is failed, so the inside code will be execute all the time.



if (
!status.ownText().toString().toUpperCase().contains("NVC")
&&
!status.ownText().toString().toUpperCase().contains("TRANSIT")
)
{
 
Cool - that would probably have worked - but I found a different way round the problem and the extracts are running now.

Thanks for coming back to me!
 
Top