Link to home
Start Free TrialLog in
Avatar of princehyderabad
princehyderabad

asked on

String - StringBuffer error..

hi experts,

This is what I'm trying to do and getting error:

public String sendMail(java.lang.String  from, java.lang.String to, java.lang.StringBuffer txtBody)
{
..
..
message.setSubject(subject);
message.setText(txtBody);
              ^Error: The method setText(String) is the type Message type is not appciable for the argument (StringBuffer)
..
}

Thx,
PH
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
use txtBody.toString()
sorry CEHJ
No problem
Avatar of ramsin112400
ramsin112400

You Should cpnvert the string buffer to string as its expecting string like this

message.setText(txtBody.toString());

Thx
ram
>>You Should cpnvert the string buffer to string as its expecting string like this

Please don't repeat answers already given
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of princehyderabad

ASKER

not STring because I'm passing StringBuffer from other java file.

Other.java
----
ruk = stmt.executeQuery(Query);
 if (ruk.next())
      {
      PrimaryKeyList.append(rs.getString("RATIONALIZE_USER_KEY"));
      PrimaryKeyList.append("\r\n");
      }
...
StringBuffer txtBody = new StringBuffer();
msgBody.append("You are receiving this notice because ......\n\n. List of  damage ID are as follows:-\n\n");
                msgBody.append(PrimaryKeyList);


Am I correct to use stringbuffer now ??
not if the methods needs a string. If it needs it a String it should be declared to expect one, and the caller should do the required conversion

mailer.sendmail(from, to, txtBody.toString());

more flexible that way.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you're calling it from various other files, then you will have to change the method-call everywhere to ensure you pass a String instead of StringBuffer. Its easier to just use toString (). Are you modifying the string-buffer too inside this method and then using that value somewhere in the calling method? If so, let it be a String-buffer.
:-)