• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

StringBuffer constructor error

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no problem compiling that program. Maybe something is wrong with yout SDK?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Weird. What do you get wnen you compile:


?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic