Re: Java & XML
aix five wrote:
Can anyone help me how to handle JAVA NullPointerException?
Is it possible to continue to run in "<>" as shown below?
Or I need to assign a new value if String A is null?
That depends on the logic of the problem domain.
Please advice. Thanks.
String AA = getXMLInfo(XXX, "YY");
String A = myDate.convert(AA, inDateFormat, outDateFormat);
String BB = getXMLInfo(VVV, "UU");
String B = myDate.convert(BB, inDateFormat, outDateFormat);
catch (NullPointerException e)
System.out.println("main: Oops, null exception caught");
<continue to run and assign
Normally you don't have a lot of code in the 'catch' block; that's the
exceptional code path and most logic should be in the unexceptional path. In
the 'catch' block you do just enough to restore sane program state - perhaps
you assign a default value to 'A'  or return prematurely from the method.
Whatever you do, you should log the exception in the 'catch'. Normal program
logic will resume outside the 'catch' with sanity restored.
'NullPointerException' ("NPE" for short) is a programmer error. Normally you
wouldn't have a 'catch' block for runtime exceptions but would fix the code so
they cannot happen. Fix your code so that the reference cannot be 'null'.
 You should follow the coding conventions, which dictate that only type
names and constants begin with an upper-case letter. Variable names (that
aren't constants) and method names should begin with a lower-case letter.
Non-constant identifiers should be in camel case - mixed case with the start
of each compound word part capitalized, as in 'SomeType' or 'aVariable'.
Avoid one-letter or similarly short, obscure variable names - what the hell is
an "AA" supposed to be? How does that name even remotely help a maintainer
understand what is going on? Spell it out with a domain-meaningful word or
phrase. C'mon - bits aren't expensive.
String documentInfo = getXMLInfo( document, "YY" );