Topic
  • 4 replies
  • Latest Post - ‏2012-06-11T20:02:04Z by TatianaHriplivii
SystemAdmin
SystemAdmin
757 Posts

Pinned topic Compiler Error

‏2011-04-22T00:04:21Z |
Hello all ...
I'm experiencing a very curious compiler error...
I have a lot of variables defined in the following fashion

static StringBuffer logstr_area = new StringBuffer() ;
static StringBuffer message_area = new StingBuffer() ;

.....etc.....

when I compile the source code the first error message I get is:
..Found java.lang.string ...required java.lang.stringbuffer or words to that effect

and from that I get about 98 compiler errors from all the references to stringbuffers I've defined ... invalid type is part of the error message.

I tried an explicit import...i.e.

import java.lang.* ;

but i still get the same error messages I'm running IBM's SDK 6 (java 1.6 ??)

any ideas and/or suggestions are welcomed

Thanks

Guy
Updated on 2012-06-11T20:02:04Z at 2012-06-11T20:02:04Z by TatianaHriplivii
  • SystemAdmin
    SystemAdmin
    757 Posts

    Re: Compiler Error

    ‏2011-04-22T15:49:58Z  
    more on this compiler error

    this is one of the many error messages I get
    src\LU62XnsCvr.java:265: incompatible types
    found : java.lang.String
    required: java.lang.StringBuffer
    message_data = "LU62XCE0513: Request File I/O Exception =" ;

    the rest are exactly like this one ...

    My question is WHY does the java compiler make such a distinction ??
    Now it's my understanding that a stringbuffer can change size dynamically.
    and simple string variables are "fixed" in size.
    SO why does it matter if one is copying a string of fixed size into a stringbuffer that
    starts out with an initial size of 16 bytes and can extend its length to accomodate the
    data it's receiving... I could understand incompatble types IF I was trying to put integer data into a "display" field.
    This however makes no sense BOTH are strings ..
  • seohulu
    seohulu
    3 Posts

    Re: Compiler Error

    ‏2011-11-22T16:20:04Z  
    at first you need to post your code snippet here, usually the java code tell you which line has the error.

    anyway, what i am guessing is that you are assigning an instance of StingBuffer directly to a string, like this:

    String a = stingBufferInstance;

    what you should do is:
    String a = stingBufferInstance.toString();

    hope that this can be helpful.

    Acoolme is an Online Marketing Software Platform And Social Community
  • seohulu
    seohulu
    3 Posts

    Re: Compiler Error

    ‏2011-11-22T16:24:56Z  
    • seohulu
    • ‏2011-11-22T16:20:04Z
    at first you need to post your code snippet here, usually the java code tell you which line has the error.

    anyway, what i am guessing is that you are assigning an instance of StingBuffer directly to a string, like this:

    String a = stingBufferInstance;

    what you should do is:
    String a = stingBufferInstance.toString();

    hope that this can be helpful.

    Acoolme is an Online Marketing Software Platform And Social Community
    sorry, it is opposite to what i am said before.

    you might be assign a string directly to string buffer, like this

    StringBuffer sb = "asdfasdfasdfa';

    you should do it like this:

    sb.append("adsfasdfafasd";
    Acoolme is an Online Marketing Software Platform And Social Community
  • TatianaHriplivii
    TatianaHriplivii
    1 Post

    Re: Compiler Error

    ‏2012-06-11T20:02:04Z  
    onceI wrote everything ok, and the teacher checked: it was written right, but I made copy-paste from a text and the complier didn't "understant" what was there. I made delede and wrote by myself - and then it worked.