GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes NPE when adding combobox selection to my jList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "NPE when adding combobox selection to my jList" Watch "NPE when adding combobox selection to my jList" New topic
Author

NPE when adding combobox selection to my jList

Sean Gomes
Greenhorn

Joined: Apr 27, 2013
Posts: 3
Hey guys.

I got a problem with my java program, and im new to java.

I get an NPE and after severals hours yesterday I gave up.

I have now created a profile in here, so I hope somebody can help me

I want to make a combobox selection, and paste it to my jList, but even if I found many solutions on google yesterday I still get this NPE

NPE says that the problem is at line 19 in my ActionHandler class

My english is alittle rusty, so I hope you understand me.


My GUI Class


My ActionHandler for GUI


NPE
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39079
    
  23
Welcome to the Ranch

Please tell us which line number in your code corresponds to the line numbers in that stack trace.
Sean Gomes
Greenhorn

Joined: Apr 27, 2013
Posts: 3
Thank you!

Im not sure what you mean ?

Can you please explain it for me?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39079
    
  23
Somewhere in the stack trace there will be a reference to a line you wrote. Which is the first line in the stack trace which you wrote? You can work it out from the numbers shown in the stack trace.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39079
    
  23
Which line does 19 refer to? Is it the same as 19 on the post?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2191
    
    7
18. public InvoiceApplication gui; // you define a variable with the value null here
19. ...
44.
45. public InvoiceApplication() {
46.
47. AcHandler actionH = new AcHandler(gui); // then you pass it to your handler and it is still null

There is no need to create an InvoiceApplicataion variable. If you want to refer to the current class you just use the java keyword "this". So your code should be:


Sean Gomes
Greenhorn

Joined: Apr 27, 2013
Posts: 3
Thank you so much Rob its works now!

Thank to all of you I will close this thread.

Have a nice day

 
GeeCON Prague 2014
 
subject: NPE when adding combobox selection to my jList