Search code examples
javastringstringbuffer

Why am I getting an incompatible types from the java compiler?


I'm a Java newbie, but I am an experienced programmer (Assembler, COBOL, C/C++, REXX)

I can't understand why the compiler is giving me the following:

[loading java\lang\Throwable.class(java\lang:Throwable.class)]
src\LU62XnsCvr.java:265: incompatible types
found   : java.lang.String
required: java.lang.StringBuffer

Code:

message_data = "LU62XCE0513: Request File I/O Exception =" ;

I've defined message_data as:

static StringBuffer message_data = new StringBuffer();

So why can't I place a simple literal String into the StringBuffer labeled message_data ? I mean BOTH are of type String .. right ??


Solution

  • Both objects may represent a string but they are thechnically not both of type string. You can create a stringbuffer from a string directly via new StringBuffer(message_data).