Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Converter in Swing help.  RSS feed

 
c cross
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15860
80
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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)"
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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?
 
Mohamed Sanaulla
Bartender
Posts: 3169
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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: 3169
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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: 3169
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this should help you with initializing the floatInput (which is a JTextField)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!