"Cannot Find Symbol" "symbol : method append(java.lang.StringBuffer)"
publicstatic String message ="";
This is the error message I receive:
xchan.java:50: cannot find symbol
symbol : method append(java.lang.StringBuffer)
location:class java.lang.String
message = message.append(new StringBuffer()).append('\n').append(s1).toString();
What am I doing wrong here?
The arrow shows up under the period between message and append.
You have one-too-many closing parenthesis.
> You have one-too-many closing parenthesis.I see an equal amount of opening and closing parentheses....
> > You have one-too-many closing parenthesis.> I see an equal amount of opening and closing> parentheses....Sorry, one of your closing parenthesis needs to be moved.
> > > You have one-too-many closing parenthesis.
> > I see an equal amount of opening and closing
> > parentheses....
>
> Sorry, one of your closing parenthesis needs to be
> moved.
To where? I'm assuming you mean the parentheses around the "new StringBuffer" but they look correct to me.
I was trying to not spoonfeed you, but I think this is what you are trying to do.message = message.append(new StringBuffer().append('\n').append(s1).toString());
> I was trying to not spoonfeed you, but I think this
> is what you are trying to do.
> [code]message = message.append(new
> StringBuffer().append('\n').append(s1).toString());[/c
> ode]
I had already tried that, but I still get the same error message as before.
message is a String; it has no append() methods (has anyone mentioned to you that strings are immutable?). You should probably be declaring message as a StringBuffer instead of a String; then your append() calls will work as expected. For more specific help, we'll need to see the complete loop or method or whatever that statement is in.
Whoops. The String class has the concat() method.
> message is a String; it has no append()
> methods (has anyone mentioned to you that strings are
> immutable?). You should probably be declaring
> message as a StringBuffer instead of a String;
> then your append() calls will work as expected. For
> more specific help, we'll need to see the complete
> loop or method or whatever that statement is in.
message = s1.substring(s1.indexOf('"') + 1, s1.length());
if(s1.charAt(s1.length() - 1) != '"')
while((s1 = bufferedreader.readLine()) != null)
{
message = message.append(new StringBuffer()).append('\n').append(s1).toString();
if(s1.length() != 0 && s1.lastIndexOf('"') == s1.length() - 1)
break;
}
if(message.length() != 0)
message = message.substring(0, message.length() - 1);
Basically what it's doing is that s1 starts with message=" and then a block of text, which it is reading from a file. It turns it into a single line of text with \n replacing the line breaks in the file, until it ends with another quotation mark. I have declared message as so:
public static String message = ""; at the end.When I change this to StringBuffer however, I get a whole new slew of errors.
I didn't mean that you should just change the declaration and expect everything to work, but I didn't know enough about what you're doing to give more specific advice. I still don't think I have enough info, but I'll post some code to illustrate my advice. import java.io.*;
public class Test
{
private static String message = "";
public static void main(String... args)
{
try
{
BufferedReader reader = new BufferedReader(new FileReader("Test.dat"));
String line = reader.readLine();
if (line != null && line.startsWith("message=\""))
{
StringBuffer sb = new StringBuffer(line.substring(line.indexOf("\"") + 1));
sb.append("\n");
while ((line = reader.readLine()) != null)
{
if (line.endsWith("\""))
{
sb.append(line.substring(0, line.length() - 1));
break;
}
else
{
sb.append(line).append("\n");
}
}
message = sb.toString();
}
System.out.println(message);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
My Test.dat file contains message="blah blah blah
blah blah blah
blah blah blah"
Basically what it is is that I recieved a java file that will allow me to post all pictures from a directory in my hard drive into a message board thread. Very useful for screenshot threads and comic books, etc. I've posted the code here: http://pastebin.ca/438282