File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Static Map ActionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Static Map ActionListener" Watch "Static Map ActionListener" New topic
Author

Static Map ActionListener

david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 58

Hi lads, i am working on a program i have it finished which is all and good,


But i am looking at making it more easier to read if any one is looking at it,

I have now used StaticMap but when i run the Program and Click on Connect i am getting the Following Errors




This is My Static Map



My Main Program


Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2848
    
  11

The error is saying that you are trying to use a null reference to call a method, and it tells you exactly where that's happening. When I look at line 308, I do see that you are trying to call setText() on an object that you never initialize. However, I don't see where you initialize anything, so you should have hit an error much earlier. It's possible you initialize the fields outside the class since they are static and package private, which is one good reason not to structure your class like this. Fields should always be declared private, and statics should always be final. It's also possible that the line numbers in your listing aren't matching what you actually have.
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 58
I do know it's not getting any info so it's giving back a null,

But just wondering is it possible to work with static maps like the one above to have text fields in one class and the action listener for that class in a different class like what I am trying to do
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
Why have you got so many static members in those classes?
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 58
I Change all the Private Text Fields to Static while trying to debug the Code,

its giving me a Null Pointer,

So i was hoping that by changing them to Static that in the Main Class.
That the Static Map Class should be able to pick them up aswell, and work without giving me a Null Pointer Catch Exception.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2848
    
  11

Let's back up a bit.

will give you a NullPointerException unless you have:

somewhere before you call it. You don't have that, so you get the NPE. Making it static doesn't take away the need to initialize it.
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 58
I've tried something like above within the Static Map, but just doesnt like the code at all,

have you got a web site that shows you an example so i could see it running and know whats going on and what is doing what, i tried parameters as well
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2848
    
  11

Probably, but an example of what? Your problem is uninitialized variables, and I gave you an example of how to initialize variables already. Maybe you could post the code that it just didn't like ... not the whole class please, just a few lines. At the same time, you could be more specific about what you mean by "didn't like". Maybe post the error message you're getting?
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 58


I tried some thing like this

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2848
    
  11

You forgot to say what Java didn't like about that.
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 58
The program when it runs doesn't do anything
Text fields are not population
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2848
    
  11

Well, that's a step forward from a NullPointerException, right? Looking through your code, I can't really figure out what your application is meant to do. In your most recent posting, you are initializing text fields in the handler for a button press. That's an unusual thing to do. Every time you press that button, you'll get an entirely new set of text fields, so you aren't working with the ones you added to your frame, and so they won't render anywhere.

It really seems to me that you're being too ambitious here. You should start with small, easy applications until you get a feel for what you're doing. Try to implement basic features first, then add features as you get the old ones working reliably.
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 58
My program is doing the following

Connection to a database pull the data from the database to an array out put the array to the text fields

I have an edit save delete button,

I'm doing the whole static map thing off my own back I dont really need to do it but I just thought it would look nice if I can have the button actions in a different class away from the main, I did the same for the connection to the database I have that on a class of it's own along with the SQL querys it makes it easy to update code without having to scroll down 200+ lines
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Map ActionListener