?
Solved

InvocationTargetException

Posted on 2007-10-02
4
Medium Priority
?
218 Views
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;
    }

+++++++++
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)
0
Comment
Question by:dkim18
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 20002852
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
 

Author Comment

by:dkim18
ID: 20002870
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
 
LVL 92

Expert Comment

by:objects
ID: 20003033
not from saveEntries(), you can't know what each method does internally.
0
 
LVL 86

Expert Comment

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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 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