Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Refactoring help  RSS feed

 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to refactor my program, so that my inner classes for my actionlistener events are one liners that call a UIController class, which just delegates the methods to other classes.

Everytime I try to do it a get the following error



Classes:
UIClass
Controller
FileLoader

In the UIClass I use inner classes for action events, and in each inner class I call the Controller class with the method I want to use. In the controller class I just make a method for each different method and call the appropriate class and method.

In my FileLoader class I am using a JFileChooser to select files to load. The showopendialog() method from the JFileChooser requires a JFrame object. At the moment I just did the following in my FileLoader class



I'm not sure if the showopendialog() is getting the right instance of the frame... I haven't done much with calling objects in different classes, so I'm not sure if I set that part up right. It's the only part that seems likes it causing the Exception. Any help is appreciated, thanks.

[ September 09, 2006: Message edited by: Bob Zoloman ]
[ September 09, 2006: Message edited by: Bob Zoloman ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is "ui.frame" null? You can do simple check by putting "System.out.println(ui.frame);" before the showOpenDialog call. It if is null, then it's probably just a matter of initializing that field.
 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like object instance is null, either in the UIForm, or the Contoller one. I'm not really sure how to fix that part. Is there any java code example of using a simple controller?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two fixes that come to mind would be either to pass a reference to the frame into the loadFile method as parameter (the clean solution, much preferred), or to call showOpenDialog with a new frame as parameter, i.e. "loadFile.showOpenDialog(new Frame())" (the hackish solution, just to get you going right now).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!