?
Solved

String - StringBuffer error..

Posted on 2006-05-10
12
Medium Priority
?
244 Views
Last Modified: 2013-12-29
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
0
Comment
Question by:princehyderabad
  • 4
  • 2
  • 2
  • +4
12 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 140 total points
ID: 16652434
Should be

message.setText(txtBody.toString());
0
 
LVL 13

Expert Comment

by:kawas
ID: 16652451
use txtBody.toString()
0
 
LVL 13

Expert Comment

by:kawas
ID: 16652453
sorry CEHJ
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 16652462
No problem
0
 
LVL 2

Expert Comment

by:ramsin112400
ID: 16652937
You Should cpnvert the string buffer to string as its expecting string like this

message.setText(txtBody.toString());

Thx
ram
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16652984
>>You Should cpnvert the string buffer to string as its expecting string like this

Please don't repeat answers already given
0
 
LVL 92

Assisted Solution

by:objects
objects earned 80 total points
ID: 16653538
> public String sendMail(java.lang.String  from, java.lang.String to, java.lang.StringBuffer txtBody)

why does you method accept a StringBuffer, probably should accept String

public String sendMail(java.lang.String  from, java.lang.String to, java.lang.String txtBody)
0
 

Author Comment

by:princehyderabad
ID: 16654420
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 ??
0
 
LVL 92

Expert Comment

by:objects
ID: 16654453
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.
0
 

Assisted Solution

by:mnshah9
mnshah9 earned 80 total points
ID: 16657537
No Problem to use StringBuffer in Other.java file but when you call method sendmail at that time you need to convert it into string or when you set  it into message you have to convert into string, because message.setText method accept only String

Solution 1)
-------------
message.setText(txtBody.toString());

Solution 2)
-------------
>> public String sendMail(java.lang.String  from, java.lang.String to, java.lang.StringBuffer txtBody)

change with

public String sendMail(java.lang.String  from, java.lang.String to, String txtBody)


and when you call this method, call like below

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

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16659798
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16660939
:-)
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question