File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringBuffer not work,help me.

 
Van Cam
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying the code.

please tell me more!
Thanks a lot.
 
Henry Wong
author
Marshal
Pie
Posts: 20823
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, you named your class "StringBuffer". So when you try to instantiate a StringBuffer class, you tried to create an instance of your class, by call the constructor that takes a string. You never provided a constructor that takes a string, hence, it is an error.

Henry
 
Van Cam
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you for quick reply.
I add the contructor in the code,so i also error at the append() method.
I think that the append() method is avaible in the StringBuffer class,Hix
it also is not work,please explanation detail or correct the code for me.
Thanks so much!

[ January 10, 2007: Message edited by: Van Cam ]
 
Van Cam
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hix,maybe i must create append() method myself?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Van Cam]: I think that the append() method is avaible in the StringBuffer class

It's not available in the StringBuffer class which you've created here, which has nothing at all to do with the StringBuffer class in the java.lang package. In general it is a bad, bad, bad idea to create a class of your own with the same name as a commonly-used library class (especially anything in java.lang). If you simply change the name of your class to something original, you will be able to use a real StringBuffer without interference.
 
Van Cam
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:
In general it is a bad, bad, bad idea to create a class of your own with the same name as a commonly-used library class (especially anything in java.lang). If you simply change the name of your class to something original, you will be able to use a real StringBuffer without interference.[/QB]

I am Sorry,I have forgotten about it,Thanks
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

Jim Yingst wrote

In general it is a bad, bad, bad idea to create a class of your own with the same name as a commonly-used library class (especially anything in java.lang).



The easiest thing to do is to rename your class.



Bad style - but running - would be this
prints:
sl after concat(): String literal!
sn after concat(): String new
sb after append(): String buffer Ya!

NB: it works but don't do this at home, kids!
Because if you do, all other classes in the same package that use java.lang.StringBuffer without explicitely indicating the java.lang package will no longer compile. They will mistake your StringBuffer class.


Yours,
Bu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic