Hello all


I am using reading a config file in which there is a entry

code_list="515,522,560,000"

while i am reading this string in my java application and using split on it and then assigning it to a string[].it is giving null pointer exception.needed code is as follows

static String[] splittArray=null;
code_req=properties.getProperty("code_list");
                        if (code_req != null || !code_req.equalsIgnoreCase(""))
                        {
                                splittArray=code_req.split(",");
                                System.out.println(code_req + " code request and splittarray" + splittArray);
                        }

output comes as follows
Reading configuration file :: ./config.cfg
"515,522,560,000" code request and splittarray[Ljava.lang.String;@a981ca
This exception is caught
READ CONFIG FILE :: java.lang.NullPointerException

For one, your if statement should be && not ||
As it is now, if it is null it attempts to do equalsIgnoreCase on that nuill reference.

That doesn't look like the exception is thrown until after the System.println on line 6, so maybe it's not the split that is the prolem.
What is the exact complete exception message (including the line number)?

For one, your if statement should be && not ||
As it is now, if it is null it attempts to do equalsIgnoreCase on that nuill reference.

this is complete code

code_req=properties.getProperty("code_list");
                        if (code_req != null && !code_req.equalsIgnoreCase(""))
                        {
                                splittArray=code_req.split(",");
                                [B]System.out.println(code_req + " code request and splittarray" + splittArray);[/B]
                        }
                        for(int n=0;splittArray!=null;n++)
                        {
                                strSub[n]=properties.getProperty("URL_SUB_"+splittArray[n]);
                                System.out.println("Url are"+strSub[n]);
                        }

java.lang.NullPointerException
at sub_unsub.readConfigFile(sub_unsub.java:82)//line in green color
at sub_unsub.main(sub_unsub.java:233)

But i am still not able to get complet array "SplitArray" after splitting the string in BOLD LINE.please suggest how i got that comma separated string into array.CURRENTLY ARRAY IN PRINTED AS
"515,522,560,000" code request and splittarray[Ljava.lang.String;@8814e9

Well, something on that line is null, even if it weren't that loop would eventually lead to an indexOutOfBoundsException since your for loop condition is corked. Either strSub is null, or properties is null (kind of doubt this one as it was used before the previous loop).

Is your problem in printing the array [Ljava.lang.String;@8814e9 ?
That's how println prints an array of Strings.
If you want to see the contents either loop thru the elements printing them one at at time or use Arrays.toString(..)

Is your problem in printing the array [Ljava.lang.String;@8814e9 ?
That's how println prints an array of Strings.
If you want to see the contents either loop thru the elements printing them one at at time or use Arrays.toString(..)

Thanks you solved my problem.

This question has already been answered. Start a new discussion instead.