• 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

Missing a piece of code used to compare an in-putted string with a key string

 
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a method for a button so when a user inputs something it then will get the string value and check it against the string value within the properties file to see if it exists.
I will post my button and method below and hopefully a fresh pair of eyes can see what I need to add so this does as it should

The properties file is called GitCommands.properties that contains -- > key = value <-- in it
I realised I have not used it correctly hence why I keep getting errors - I am lost on how to use it, I think perhaps that may be the issue here? I need to reference the file but I am doing it wrong?
When I do use that piece of code I get null pointer exception too

This is my button:




This is the code for my method:


I understand I am missing my piece of code where it states " //determine whether the string is equal to the property file key string" I understand the logic fine but not actually coding it,could anyone lend a hand?
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


this is not the way you compare a String, it should be

 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah of course, thank you, I've been looking at this for far too long now I think! :P I'll be very happy once I've got this finished

Still confused as to why this doesn't work
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Provide us some more input so that we can try to figure it out.
 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added some more information, I hope it helps to solve my issue - I believe I know it but I don't know how to fix it
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So far as I understood, you have a property file. User enters a key to search, if this key is found, in the property file, you display a success message or else you display message. Is this what you want?
 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah that is what I want to be able to do

Would it something more like this that I would use? -> GitCommands.containsKey("Key");
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in theory now, if my button has never changed and my method now looks like this:



*Update : It didn't work I still get given a null pointer exception even using that piece of code you you showed me how to use correctly

Thank you for helping, much appreciated by the way
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are still doing it wrong. Try this



and make sure GitCommands is not null.
 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It still says:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at HelpSystem.FindSelectedKey(HelpSystem.java:382)


line 382 is:


It always stops at that point in debug- I wanted to check to see if it was definitely that

 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GitCommands seems to be null.
 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order to fix that would I have to make it as static final Properties rather than just properties as I did have it set up like that at one point
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show the complete code if you can.
 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my full code - I have a fully functional Jtree with key commands in on it. I hope this makes sense to you, I cut some imports out as it was just stuff to do with components out the designer such as jscrollpane and such, thankyou for helping,let me know if I should cut the code down some more!


 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made it bit simpler, see if this helps

 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One sec i'll check again
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have used simple flowlayout with a size 200,200. You need to maximize the window to provide the input. Once input is given the key you wish to search, press the button , minimize the window and see what it shows in console.
 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah that worked - I just need to incorporate that into my application now as I have a split tabbed,split screen app.

One tab is a search, other is a lookup containing a Jtree then down the right I have my panel

Thanks for taking the time to help me on this,you've really helped!
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome.
 
Alice Hampton
Ranch Hand
Posts: 217
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very helpful, If I ever get stuck again I'm asking you haha, but no in all seriousness my code works great now!
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's great. It's good to know that your code is working great now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic