Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Incompatiable variable types

 
LaTeef Lusk
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11879
195
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11879
195
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Durn, beaten by a few minutes by Ulf.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48967
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to Beginners, where Rob and I can race to post the next answer
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic