Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help in Objects/Constructors

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm taking a java 2.0 course and have had problems with constructors and making objects. I tried the following code:

Code:
class StringBufferDemo	{
	public static void main(String args[])	{
		StringBuffer sb1 = new StringBuffer();
		StringBuffer sb2 = new StringBuffer(30);
		StringBuffer sb3 = new StringBuffer("abcde");
		System.out.println("sb1.capacity = " + sb1.capacity());
		System.out.println("sb1.length = " + sb1.length());
		System.out.println("sb2.capacity = " + sb2.capacity());
		System.out.println("sb2.length = " + sb2.length());
		System.out.println("sb3.capacity = " + sb3.capacity());
		System.out.println("sb3.length = " + sb3.length());
		}
}

and got the following errors:

Code:
C:\Java2\Chapter2\2d8ex1\StringBufferDemo.java:4: cannot resolve symbol
symbol  : constructor StringBuffer  (int)
location: class StringBuffer
		StringBuffer sb2 = new StringBuffer(30);
                                   ^
C:\Java2\Chapter2\2d8ex1\StringBufferDemo.java:5: cannot resolve symbol
symbol  : constructor StringBuffer  (java.lang.String)
location: class StringBuffer
		StringBuffer sb3 = new StringBuffer("abcde");
                                   ^
C:\Java2\Chapter2\2d8ex1\StringBufferDemo.java:6: cannot resolve symbol
symbol  : method capacity  ()
location: class StringBuffer
		System.out.println("sb1.capacity = " + sb1.capacity());
                                                          ^
C:\Java2\Chapter2\2d8ex1\StringBufferDemo.java:7: cannot resolve symbol
symbol  : method length  ()
location: class StringBuffer
		System.out.println("sb1.length = " + sb1.length());
                                                        ^
C:\Java2\Chapter2\2d8ex1\StringBufferDemo.java:8: cannot resolve symbol
symbol  : method capacity  ()
location: class StringBuffer
		System.out.println("sb2.capacity = " + sb2.capacity());
                                                          ^
C:\Java2\Chapter2\2d8ex1\StringBufferDemo.java:9: cannot resolve symbol
symbol  : method length  ()
location: class StringBuffer
		System.out.println("sb2.length = " + sb2.length());
                                                        ^
C:\Java2\Chapter2\2d8ex1\StringBufferDemo.java:10: cannot resolve symbol
symbol  : method capacity  ()
location: class StringBuffer
		System.out.println("sb3.capacity = " + sb3.capacity());
                                                          ^
C:\Java2\Chapter2\2d8ex1\StringBufferDemo.java:11: cannot resolve symbol
symbol  : method length  ()
location: class StringBuffer
		System.out.println("sb3.length = " + sb3.length());
                                                        ^
.\StringBuffer.java:4: cannot resolve symbol
symbol  : constructor StringBuffer  (int)
location: class StringBuffer
		StringBuffer a = new StringBuffer(10);
                                 ^
9 errors

I took this script straight out of a book...can anyone tell me what's wrong?
 
Hi,

I compiled the same codes and it didn't give me any errors. I guess the errors occured maybe because you didn't set your classpaths correctly or that the version of jdk that you are using isn't updated.

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top