Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringBuffer constructor error

 
Jerry Bustamente
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

:-)

JerryB
 
Tybon Wu
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no problem compiling that program. Maybe something is wrong with yout SDK?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Weird. What do you get wnen you compile:


?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jerry Bustamente
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

:-)

JerryB
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic