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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use txtBody.toString()
sorry CEHJ
No problem
You Should cpnvert the string buffer to string as its expecting string like this
message.setText(txtBody.to String());
Thx
ram
message.setText(txtBody.to
Thx
ram
>>You Should cpnvert the string buffer to string as its expecting string like this
Please don't repeat answers already given
Please don't repeat answers already given
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
not STring because I'm passing StringBuffer from other java file.
Other.java
----
ruk = stmt.executeQuery(Query);
if (ruk.next())
{
PrimaryKeyList.append(rs.g etString(" RATIONALIZ E_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(PrimaryKeyL ist);
Am I correct to use stringbuffer now ??
Other.java
----
ruk = stmt.executeQuery(Query);
if (ruk.next())
{
PrimaryKeyList.append(rs.g
PrimaryKeyList.append("\r\
}
...
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(PrimaryKeyL
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.
mailer.sendmail(from, to, txtBody.toString());
more flexible that way.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
:-)