Posted on 2007-10-02
Last Modified: 2010-04-01
Hi Experts,

I have this method(generic-like) that saves entries from strusts action form and analyze for some purpose. However, I am having this error and I am checking null case in my code. any idea?


public void saveEntries(ActionForm aForm, boolean fromValBtn) {
        PropertyDescriptor pd[] = PropertyUtils.getPropertyDescriptors(aForm);
for(int i=0; i<pd.length; i++){
            Method reader = PropertyUtils.getReadMethod(pd[i]);

            if(reader != null && (reader.toString().length() > 0) ){
                Object obj = reader.invoke(aForm,new Object[] {});

getter from the form

public String getFmriId() {
        fmriId = functmriseq.getFunctmriseqId().toString();
        return fmriId;

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(
      at java.lang.reflect.Method.invoke(
      at org.kki.dcn.struts.utils.DcnDispatchUtilAction.saveEntries(

Caused by: java.lang.NullPointerException
      at org.kki.dcn.hibernate.mriSeq.Seqpar.getAmriId(
Question by:dkim18
    LVL 92

    Accepted Solution

    the NPE is happening in getAmriId at line 538
    check that line for any references to vars that could be null, and add null checks there as required

    Author Comment

    yeah..i can see that. since that saveEntries method handles many forms, is there any way that I can handle such a case from that method?
    LVL 92

    Expert Comment

    not from saveEntries(), you can't know what each method does internally.
    LVL 86

    Expert Comment

    Isn't it all your own code? If so, why not ensure that the save is not invoked without non-null parameters?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now