PDA

View Full Version : StringBuffer @ java


daniel_g
10-07-2006, 05:27 AM
I'm having trouble trying to use StringBuffer() on the following code. The error I'm getting is:
ChangeBase.java:91: non-static method append(char) cannot be referenced from a static context.


public void actionPerformed(ActionEvent e)
{
//....
for(int j = 0; j<count; j++){
test = ChangeBase.pop();
System.out.println(test);
StringBuffer.append(str.charAt(test));//where str is just a string. This is line 91.
}
}
StringBuffer buf = new StringBuffer();
jtfResult.setText(buf.toString());
//...

Anyone has an idea what the error is refering to?

Brandoe85
10-07-2006, 05:47 AM
You need to create an instance of the StringBuffer, as you are here:
StringBuffer buf = new StringBuffer();

Good luck;

daniel_g
10-07-2006, 07:35 AM
Thanks brand, at first I was wondering what the heck you meant, since StringBuffer buf = new StringBuffer() was my instance. But then I realized it had to be moved to another place(to a line before the loop started), and changed
StringBuffer.append(str.charAt(test));
to
buf.append(str.charAt(test));
That worked. Again, many thanks.