aspose file tools*
The moose likes Beginning Java and the fly likes StringBuffer not work,help me. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StringBuffer not work,help me." Watch "StringBuffer not work,help me." New topic
Author

StringBuffer not work,help me.

Van Cam
Greenhorn

Joined: Aug 05, 2006
Posts: 13
I am trying the code.

please tell me more!
Thanks a lot.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19004
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Van Cam
Greenhorn

Joined: Aug 05, 2006
Posts: 13
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

Joined: Aug 05, 2006
Posts: 13
Hix,maybe i must create append() method myself?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[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.


"I'm not back." - Bill Harding, Twister
Van Cam
Greenhorn

Joined: Aug 05, 2006
Posts: 13
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

Joined: Aug 25, 2006
Posts: 1274
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.


all events occur in real time
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: StringBuffer not work,help me.