• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

writeUTF and JComboBox

 
Greenhorn
Posts: 11
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Tiarnach
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ??? '
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic