• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to sovle these two errors~~~help~~~

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i run my program,errors appear:

"WriteString(java.lang.String) in FileOutput cannot be applied to (java.lang.Object)

this is anothor program's error:

"incompatible types - found java.lang.Object but expected java.lang.String"

i cant get it! anyone help me solve both of them???
thanks a lot~~~
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both the same problem - cast your Object to a String by placing the cast (String) in front of it



should be



I am assuming that the reference you are giving to the WriteString is, in fact, a Strnig object of course - if it is a different type then this will not work.
 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One other point - just a matter of convention - methods in Java are usually written with the first character lowercase and the remaining words denoted by an uppercase character.

If WriteString is a method - it should really be writeString
[ November 16, 2005: Message edited by: Rick Beaver ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Duplicate of this post
 
Alex cordes
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rick Beaver:
Both the same problem - cast your Object to a String by placing the cast (String) in front of it



should be



I am assuming that the reference you are giving to the WriteString is, in fact, a Strnig object of course - if it is a different type then this will not work.



thanks for ur reply~~~yes~~~i make the 1st one correct, but cant do it with the 2nd one:
the wrong code is:
"String name = names.get(i);"
how to change the type of it?
 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Alex cordes
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rick Beaver:



oh~~~man~~~how fast can u be??? u r amazing!!!~~~thanks a lot~~~ )))
 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem
 
I child proofed my house but they still get in. Distract them with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic