===
* Error code: * correct code:
If (string) RS [4]). Equals ("C "))...{
//
}
If ("C". Equals (string) RS [4])... {
//
}
* Cause: Rs [4] may be null, leading to Null Object Reference and throwing an exception.
===
Code optimization
* Original code: * replace:
Cpvo. setprodtype (staticparameters. getproducttype (RS [4]);
If (string) RS [4]). Equals ("C "))...{
Cpvo. setprodtype ("general products ");
}
Else if (string) RS [4]). Equals ("S "))...{
Cpvo. setprodtype ("solution ");
}
Else
Cpvo. setprodtype (string) RS [4]);
The definition class staticparameters. See the staticparameters. Java file.
Other static parameters have similar problems, such as binding a flag.
* Code:
Import java. util. hashmap;
Import java. util. Map;
Public class staticparameters
...{
Private Static map producttypes = NULL;
Static ...{
// Initialize a set of Static Parameters
Initproducttypes ();
}
Private Static void initproducttypes ()
...{
If (producttypes = NULL)
...{
Producttypes = new hashmap ();
Producttypes. Put ("C", "General Products ");
Producttypes. Put ("S", "solution ");
}
}
Public static string getproducttype (string code)
...{
String value = (string) producttypes. Get (CODE );
Return Value = NULL? Code: value;
}
}