wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "writeUTF and JComboBox" Watch "writeUTF and JComboBox" New topic
Author

writeUTF and JComboBox

Matthew Buska
Greenhorn

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\BillPayer.java:180: cannot resolve symbol
symbol : method writeUTF (java.lang.Object)
location: class java.io.DataOutputStream
output.writeUTF(pmt.getSelectedItem());

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

Thanks,

Matt

[ 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
Sheriff

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: http://aspose.com/file-tools
 
subject: writeUTF and JComboBox
 
Similar Threads
Align JLabel, JTextField inside TitledBorder
connection problem
What's up with a random number like this being displayed 889193265?
Using External Data(need help before Monday)
panels not displayed fullly in Jframe