jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes StringBuffer constructor error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "StringBuffer constructor error" Watch "StringBuffer constructor error" New topic

StringBuffer constructor error

Jerry Bustamente
Ranch Hand

Joined: May 24, 2004
Posts: 90
Good Evening,

I'm chasing my tail, again, and would appreciate any help.

I received the following error message for line 3:

"The constructor StringBuffer(String) is undefined."

Here is the short bit of code:

public class TestStuff {

public static void main(String[] args) { // line 1
String x1 = "12ab"; // line 2
StringBuffer bc = new StringBuffer("34cd"); // line 3
byte y = 1; // line 4
System.out.println(x1 + y); // line 5
System.out.println(bc.toString() + y); // line 6

Thank you for your help.


Tybon Wu
Ranch Hand

Joined: Jun 18, 2002
Posts: 84
I have no problem compiling that program. Maybe something is wrong with yout SDK?

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Weird. What do you get wnen you compile:


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Do you somehow have a class named either "String" or "StringBuffer" which you defined yourself, rather than using the standard Java library versions? Check your classpath carefully - you may have some old files lying around somewhere you've forgotten about.

Does your JDK installation still have a file named rt.jar? (Should be inside the jre/lib directory.) That's where most of your classes should be defined. If it's missing for some reason, then the problem you describe is one of many you'll be having in the near future.

"I'm not back." - Bill Harding, Twister
Jerry Bustamente
Ranch Hand

Joined: May 24, 2004
Posts: 90
Thank you to Tybon, Barry, and Jim.

I had previously created a class name StringBuffer in the same package. After I deleted the class and recompiled the code it worked fine.

Thanks again guys.


I agree. Here's the link: http://aspose.com/file-tools
subject: StringBuffer constructor error
It's not a secret anymore!