Results 1 to 3 of 3
  1. #1
    mlibot is offline Member
    Join Date
    Sep 2009
    Posts
    44
    Rep Power
    0

    Default How to do this with StringBuffer???

    Hi All, I'm using netbeans and i have a project i call this "Activity" inside this project i have a Main Class which is default once you created a project:
    I've created another class i call this "StringBuff"

    this is my StringBuff class
    Java Code:
    package activity;
    
    public class StringBuff {
    
        public void getStringBuff(StringBuffer strbfr){
    
            String str = new String("Hello World!");
            strbfr.append(str);
            System.out.print(strbfr);
    
        }
    }
    my problem is I do not know how to access this in my Main class im trying to access like this but i have an error:
    Java Code:
    package activity;
    
    public class Main {
    
        public static void main(String[] args) {
            StringBuff sb = new StringBuff();
            sb.getStringBuff();
        }
        
    }
    anyone???
    help me out of here...

    thanks in advance

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    The method header states, that an argument of the type StringBuffer should be passed when calling your method:
    Java Code:
    public void getStringBuff(StringBuffer strbfr)
    So you should do this:
    Java Code:
    public class Main {
    
        public static void main(String[] args) {
            StringBuff sb = new StringBuff();
            [B]StringBuffer s = new StringBuffer();[/B]
            sb.getStringBuff([B]s[/B]);
        }
        
    }
    A tip, getStringBuff is not a good name for a void method, as the get implies a getter method which returns a value. And also, I'm not really sure what exactely you're trying to do here.

  3. #3
    mlibot is offline Member
    Join Date
    Sep 2009
    Posts
    44
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 03-04-2009, 06:03 AM
  2. Replies: 1
    Last Post: 03-03-2009, 05:27 AM
  3. Should I use StringBuffer?
    By GenkiSudo in forum New To Java
    Replies: 7
    Last Post: 09-21-2008, 12:39 PM
  4. StringBuffer
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-08-2007, 08:33 AM
  5. Help with StringBuffer
    By Marcus in forum AWT / Swing
    Replies: 2
    Last Post: 07-04-2007, 05:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •