This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes writeUTF and JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "writeUTF and JComboBox" Watch "writeUTF and JComboBox" New topic

writeUTF and JComboBox

Matthew Buska

Joined: Jul 27, 2004
Posts: 11

I'm creating a program that will save what the user enters into a file and in the end check to see if what the user typed in is correct and have it display whether or not it is correct. My problem is I created a JComboBox and I'm wanting to save whatever the user clicked on in the JComboBox and its giving me this error:

C:\Documents and Settings\sth-g200\Desktop\ cannot resolve symbol
symbol : method writeUTF (java.lang.Object)
location: class

If anyone can take a look at my code and point me in the right direction it would be greatly appreciated.



[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ August 08, 2004: Message edited by: Dirk Schreckmann ]
Liam Tiarnach
Ranch Hand

Joined: Aug 06, 2004
Posts: 51
JComboBox's getSelectedItem() method returns an Object type... and DataOutputStream does not have a writeUTF() method that takes an Object as an arguement...

One possible solution, cast said Object to a String...

It compiles and work fine on my PC now after resolving the error...

Hope this helps...

- Liam...<br />- ' He who never sleeps... '
Liam Tiarnach
Ranch Hand

Joined: Aug 06, 2004
Posts: 51
Of course, you can also call the returned Object's toString() method...
(Imagine that, calling the toString method on a String )

and leave the casting alone, since we know that the Object returned is a String...

And it looks better than casting...

- ' Aye, it be bright out, whered me put me ale ??? '
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: writeUTF and JComboBox
It's not a secret anymore!