0

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
  • meman is null, StackTrace is always nice Commented Mar 4, 2011 at 9:48

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

row27.get method can throw NPE just as fine (somewhere inside), but my bet is meman for the null
yes meman is initialized as null i.e String meman[] = null; and there was no issue if meman is simple string variable. but i need it to be an array as in future this piece of code is looped and i want to store all the values while looping.
@techocrat: Well you're trying to dereference a null variable, so of course it's blowing up. Either you need to create the array beforehand, or preferably change to using a List<String> so you don't need to know the size beforehand.
its not throwing exception but its printing some peculiar values like [Ljava.lang.String;@1bf3d87 i've initialized meman as String meman[] = new String[1];
@technocrat: Right, so now presumably you're printing meman instead of meman[0]. As I said in my edit, learn basic Java before continuing. You're doing yourself no favours by trying to continue with your current project before you understand the fundamentals of the language.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.