• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Static Map ActionListener

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why have you got so many static members in those classes?
 
david foley
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I tried some thing like this

 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You forgot to say what Java didn't like about that.
 
david foley
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The program when it runs doesn't do anything
Text fields are not population
 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic