This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Incompatiable variable types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Incompatiable variable types" Watch "Incompatiable variable types" New topic
Author

Incompatiable variable types

LaTeef Lusk
Greenhorn

Joined: Mar 28, 2009
Posts: 15
I am trying to compile my applet and keep getting the following error. It keeps telling me that it found a Variable String type but I am only defining type int. My code is below. Can anyonejust point me in the right direction please. Thanks!






[Edit: put code between [code] and [/code] UBB tags.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
Take a look at the javadocs of the java.awt.TextField class. You'll find that it has neither a "setText(int)" nor an "int = getText()" method. That's what the error message is telling you.

You'll need to convert the int to a String for use with the setText method, and you need to convert the String result of getText to an int to use it on your program.

(I'll move the topic to a different forum, as there's nothing applet-specific about it.)
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

In lines 7 & 8 you have defined farenheitInput and celsiusInput as TextField. According to the API, "A TextField object is a text component that allows for the editing of a single line of text."

For your first error at line 43, you are using the getText() method to get the data from the farenheitInput field. According to the API (and as the name suggests), this method "Returns the text that is presented by this text component. By default, this is an empty string."

So the error message is correct: it found that you are getting text from the TextField and attempting to assign this text to an integer.

What you need to do in this case is find a method that will convert a String to an int. I would recommend looking at the Integer class, and seeing if there is a method that can parse the String for you.

Does this help you determine what the likely cause of the second error is?


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Durn, beaten by a few minutes by Ulf.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
. . . and welcome to Beginners, where Rob and I can race to post the next answer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Incompatiable variable types