null pointer exception

153 Views Asked by At

the value memanufacturer is retrieved from xml document using jdom and when this value is assigned to meman array it throws NullPointerException.

Element memanufacturer = (Element) row27.get(j9);
        meman[0] = memanufacturer.getValue();

what could be the posssible mistake.

Thanks

1

There are 1 best solutions below

7
On

Assuming the exception by the second line of code, there are two obvious possibilities:

  • memanufacturer may be null
  • meman may be null

We can't tell which of these is the case, but you should be able to.

EDIT: Okay, so now we know that meman is null, that's the problem. I would suggest you use a List<String> instead:

List<String> meman = new ArrayList<String>();

...
Element memanufacturer = (Element) row27.get(j9);
meman.add(memanufacturer.getValue());

Using a List<String> instead of an array means you don't need to know the size before you start.

However, the fact that you didn't understand the error suggests you should really read a good introductory Java book before going any further with a real project. You should definitely understand how arrays, collections etc work before dealing with XML and the like. It will save you a lot of time in the long run.