Web Analytics Made Easy -
StatCounter StringBuffer @ java - CodingForum

Announcement

Collapse
No announcement yet.

StringBuffer @ java

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • StringBuffer @ java

    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.

    Code:
    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?

  • #2
    You need to create an instance of the StringBuffer, as you are here:
    StringBuffer buf = new StringBuffer();

    Good luck;
    -Brando
    Why using tables for eating is stupid!

    Comment


    • #3
      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.

      Comment

      Working...
      X