Two Laptop Bag*
The moose likes Struts and the fly likes null pointer exception in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "null pointer exception in struts2" Watch "null pointer exception in struts2" New topic
Author

null pointer exception in struts2

Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
We all know that the variable name in Action class should be name of the html tag...

I have something like this





The variable names in action class:
private String conceptName;
private String attributeName;
private String addDTList;

I also have get,set methods for these...

On click on submit

When I print the above values its only printing addDTList while the other 2 are null,,,why is that so??


Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Can you show us the code of your action and what you are doing in the addRow('vocab','Add') method...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
code for addRow() method





and here is the action class...





The output on button click is as follows...

--------------------------------------------------------
Inside Vocabulary Action Class
The addVocOk is :-->Ok
saveVocabulary-->null
gotoRuleset-->null
--- it's in addVocabulary !!!
The vals are :--->,,Integer
The npe is :--java.lang.NullPointerException


-------------------------------------------------------




Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

I'm clueless what you are trying to do with that method in JS as the dynamic row that you create will be of no use as the page will be posted back. And what's the use of these two lines
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Also in your action, is the field public Attribute attribute; initialized anywhere?? The line The vals are :--->,,Integer in your output shows that the values of conceptName and attributeName are empty and not null...
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Hi Ankit,

I want to add rows dynamically and also allow selection of rows on mouse click (delete,modify both UI and DB)...that's what i am trying to do...

yes the page is being posted back and being a tyro am struggling how to avoid it.

I guess I should create objects of concept and attribute there!

Those 2 lines are incorrect...removed!

Any other suggestions and solutions from your side would be of great help...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

If you want to add dynamically on the server without the page posting back, then you'll have to use an AJAX request. To stop postback of the page, either make the OK button a normal button instead of submit button or return false from the addRow method...
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
But If I make OK or normal button, it cuts the interaction with action class and nothing happens...only submit would allow interaction with Action class,itsn't it?correct me I f I am wrong.

Also,congrats on that scjp score...I am writing SCJP 6.0 on NOV 8th as it was a bit haste due to some reasons and I have zero preparation...Do you think I can make the cut? I will be starting my preparation today ans some inputs,papers etc would be of great help.Thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's why the previous comment said to use Ajax.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Pradeep Adibatla wrote:I am writing SCJP 6.0 on NOV 8th as it was a bit haste due to some reasons and I have zero preparation...Do you think I can make the cut? I will be starting my preparation today ans some inputs,papers etc would be of great help.Thanks!

So you are going to rely on 9-10 days of preparation?? That's not good. The SCJP exam is not that easy to crack. Why don't you postpone the exam a bit. Also for further discussion on this, start a new thread in the SCJP Forum...
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
In my above mentioned JavaScript I want to add rows and do mouseover and out for all the rows I add and then select any row but alas i could do that only with the recent row added...what should be the change? help...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null pointer exception in struts2