Link to home
Start Free TrialLog in
Avatar of mitrakis
mitrakisFlag for Germany

asked on

trim() won't work for MSIE4.x

In my applet I use trim() to remove whitespaces from a string.
Unfortunately, I noticed that browsers with e.g. Java1.1.2 return an error on this method.
Browsers with e.g. Java1.1.5 work fine (MSIE4.x not at all).
Are there any (maybe simple) altenatives I dunno ?
I just want to remove leading spaces in my string.

Best regards
-Stavi-
ASKER CERTIFIED SOLUTION
Avatar of fontaine
fontaine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mitrakis

ASKER

fontaine,

let me test this on monday, then I'll give feedback.
THX for help.

Best regards
-Stavi-


Oh no...something happened I didn't expect...=:-((

Not trim() is the problem, it's String (byte[]) instead !
Now, where trim() is "replaced", I get an error again, so I found out that it's String(byte[]) which causes all my problems...

I think I have to use something like String(StringBuffer) to make my applet available for almost all browsers ?!

If you could support me on how to read byte by byte with "StringBuffer" I'll increase points to 75.
Please tell me if this is not ok for you...(then I'll try to post a new Q !) in any case you'll get current credits coz your suggestion worked for me.

Best regards
-Stavi-
Avatar of fontaine
fontaine

Could you verify that you are actually not trying to pass a null array? Do something like:

byte bytes[] = ...

if (bytes == null) {
      System.out.println("bytes == null");
} else {
      System.out.println("bytes <> null");
}

String myString = new String(bytes); etc.

and have a look at the Java console.

Also, what is exactly the error you have, a NullPointerException?
fontaine,

definitely not NULL.

here's the error msg from the console:
# Applet exception: java.lang.String: method <init> ([BII)V not found
java.lang.NoSuchMethodError: java.lang.String: method <init> ([BII)V not found at StreamLstnr.run(StreamLstnr.java:42)

The chars B and V seem to be from "BVLAB12.fh-reutlingen.de" which is the name of the machine I connect to and which I have to analyze in my applet.

line 42 in code is:
sPadding += new String(b, 0, nread);

where b is:
byte b[] = new byte[cc.MAXBUFLEN];
and nread from type "int"

THX a lot for help
-Stavi-
OK, it seems that the browser does not support JDK 1.1 (new String(byte[], int , int) is a JDK
1.1 constructor). Try out the following:

Before:
sPadding += new String(b, 0, nread);

After:
sPadding += new String(b, 0, 0, nread); // JDK 1.0.2 way...
pretty kewl !

never thought that this could work...but it works =:-))

Best regards and THX again
-Stavi-

P.S.:
increased pts. to 75...hope this is ok.