aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Converter in Swing help. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Converter in Swing help." Watch "Converter in Swing help." New topic
Author

Converter in Swing help.

c cross
Greenhorn

Joined: Dec 01, 2011
Posts: 4
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
Bartender

Joined: Aug 16, 2005
Posts: 12909
    
    3

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).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
c cross
Greenhorn

Joined: Dec 01, 2011
Posts: 4
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

Joined: Aug 25, 2003
Posts: 227

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

Joined: Sep 08, 2007
Posts: 2926
    
  15

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?


Mohamed Sanaulla | My Blog
c cross
Greenhorn

Joined: Dec 01, 2011
Posts: 4
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

Joined: Sep 08, 2007
Posts: 2926
    
  15

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

Joined: Dec 01, 2011
Posts: 4
How would i go about initialising it?
Sorry if this sounds like a really stupid question.
Mohamed Sanaulla
Bartender

Joined: Sep 08, 2007
Posts: 2926
    
  15

this should help you with initializing the floatInput (which is a JTextField)
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Converter in Swing help.
 
Similar Threads
Opening a new window.
Adding JMenus to EditPanes
help me I can't work the tree well
Removing user-interface components- HELP!
coding a texteditor: want to open a separate option window