This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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.
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic