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:
and got the following errors:
I took this script straight out of a book...can anyone tell me what's wrong?
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?