• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Converter in Swing help.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
i'm trying to produce a temperature converter in swing that uses a menu to select between c to f or f to c, from here someone can enter in the value click go and then they receive the answer.
I'm struggling with my jlabel section as a null error.
What i want it to look like is:
Select a type : (drop down menu)
Type in number: (box to type in) (go button)
answer will appear on this line.

I keep getting an error i cant solve with this code:

The error occurs in the inputPanel line and i dont know waht to do.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

c cross wrote:
The error occurs in the inputPanel line and i dont know waht to do.


Is it a compile error or a runtime error? And what exactly is the error message? (Error messages contain very valuable information that gives a hint about what's wrong. It's much easier to help you if you tell us exactly what the error message is).
 
c cross
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
When i get rid of the inputpanel area i get no error. However, when i place it back in i get this error:
"Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1045)
at java.awt.Container.add(Container.java:365)
at temperatureConverter.<init>(temperatureConverter.java:66)
at temperatureConverter.main(temperatureConverter.java:110)"
 
Ranch Hand
Posts: 227
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The line number shown in stack-trace is 66, whereas in your code there is no executable statement at line 66. Please paste the actual code, or equivalent error.

The error you have mentioned can only mean one thing - the component being passed in add() is null. Look closely in your actual code. Is there a copy-pasted reference which is not initialised yet?
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More of Swing'ish query, hence moving to appropriate forum.

Try to find out the line at which the NullPointerException is being thrown, and see if the references being used in the line are initialized before being used?
 
c cross
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this.inputPanel.add(this.floatInput); is the line 66 on my computer. Hope this helps
i can post the whole file if you wish.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

c cross wrote:this.inputPanel.add(this.floatInput); is the line 66 on my computer. Hope this helps
i can post the whole file if you wish.



Are you initiaizing the floatInput? From the code you have posted, it doesn't look like
 
c cross
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would i go about initialising it?
Sorry if this sounds like a really stupid question.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this should help you with initializing the floatInput (which is a JTextField)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic