Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

conversions  RSS feed

 
akoda Svenson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some code like this

int intTest;

intTest = JOptionPane.showInputDialog(this,"Add some text here", "test").length();

I will not compile I get this error:
Error(62,14): method showConfirmDialog(mypackage2.Frame1, int) not found in class javax.swing.JOptionPane

What does that mean. I suspect it is a conversion issue but can I convert test from a "TextBox" to a numeric value in one step??

Thanks
koda
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

intTest = JOptionPane.showInputDialog(this,"Add some text here", "test").length();



I will not compile I get this error:
Error(62,14): method showConfirmDialog(mypackage2.Frame1, int) not found in class javax.swing.JOptionPane


Your code and your problem are not related.
[ July 07, 2005: Message edited by: George Bolyuba ]
 
akoda Svenson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry when I posted I missed a line of code
code:
int intTest;
intTest = JOptionPane.showInputDialog(this,"Add some text here", "test").length();

JOptionPane.showConfirmDialog(this, intTest); //Line 62

koda
 
Struan Kerr
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem is that the signature for the method in line 62 is:

showInternalConfirmDialog(Component parentComponent, Object message)

but intTest is an int, which is a primitive and not an Object, so you must create an Object such as an Integer or a String from it.

So the second parameter passed to the method in line 62 should be something like either:

new Integer(intTest)
or
Integer.toString(intTest)

Hope that helps.

Struan
 
akoda Svenson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks that did it

Here is what I used

int intTest;

intTest = JOptionPane.showInputDialog(this,"Add some text here", "test").length();

JOptionPane.showConfirmDialog(this, Integer.toString(intTest));

It is strange to me that I have to use int for declaration but then Integer for toString???

koda
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because an int is a primitive and thus does not support method calls. An Integer is an object that does support method calls.
 
akoda Svenson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joel McNary:
That's because an int is a primitive and thus does not support method calls. An Integer is an object that does support method calls.


Thanks. I'll have to read on that.

koda
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!