InvocationTargetException

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;
    }

+++++++++
java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.kki.dcn.struts.utils.DcnDispatchUtilAction.saveEntries(DcnDispatchUtilAction.java:155)
&
&
&

Caused by: java.lang.NullPointerException
      at org.kki.dcn.hibernate.mriSeq.Seqpar.getAmriId(Seqpar.java:538)
dkim18Asked:
Who is Participating?
 
objectsCommented:
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
0
 
dkim18Author Commented:
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?
0
 
objectsCommented:
not from saveEntries(), you can't know what each method does internally.
0
 
CEHJCommented:
Isn't it all your own code? If so, why not ensure that the save is not invoked without non-null parameters?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.