Marco Fedele
Marco Fedele

Reputation: 2148

Applet java throws exception with chrome

I'm developing a Django site with an applet Java.

Some days ago the applet start to fail loading in my chrome browser. I was still in developing and I tought that was a cache problem, so to test I started to use firefox.

At today the applet is developed at 90%, and on firefox works smoothy. No problems at all.

So I was working on some JS and I opened chrome (like its debugger), so I cleaned the chrome's cache folder and the java plugin cache, and I open the site.

The applet failed to load. Here is the error:

 java.lang.reflect.InvocationTargetException
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
     at sun.applet.PluginAppletSecurityContext$5.run(PluginAppletSecurityContext.java:943)
     at java.security.AccessController.doPrivileged(Native Method)
     at sun.applet.PluginAppletSecurityContext.handleMessage(PluginAppletSecurityContext.java:940)
     at sun.applet.AppletSecurityContextManager.handleMessage(AppletSecurityContextManager.java:70)
     at sun.applet.PluginStreamHandler.handleMessage(PluginStreamHandler.java:235)
     at sun.applet.PluginMessageHandlerWorker.run(PluginMessageHandlerWorker.java:78)
 Caused by: java.lang.NumberFormatException: For input string: "0,000000"
     at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1241)
     at java.lang.Double.valueOf(Double.java:504)
     at java.lang.Double.<init>(Double.java:597)
     ... 10 more
 java.lang.NullPointerException
     at sun.applet.PluginAppletViewer.getMember(PluginAppletViewer.java:1020)
     at netscape.javascript.JSObject.getMember(JSObject.java:155)
     at objects.CommunicationWithJS.parseFloors(CommunicationWithJS.java:75)
     at main.MapGenerator.start(MapGenerator.java:27)
     at sun.applet.AppletPanel.run(AppletPanel.java:476)
     at java.lang.Thread.run(Thread.java:722)

The strange thing is that on Firefox works with no problems...

On loading, the applet calls some JS on the page to load a Json from the site. This Json is than passed to the applet.

The communication between the applet and the page is managed by the netscape library.

The JS that loads the JSON:

    function getFloors() {
            var xmlHttp = null;

            xmlHttp = new XMLHttpRequest();
            xmlHttp.open( "GET", GET_FLOORS, false );
            xmlHttp.send(null);
            var json = JSON.parse(xmlHttp.responseText);

            return json;
    }

And the code on the applet:

public Floor[] parseFloors(URL codebase) {

    JSObject jsonFloors = (JSObject) window.eval(GET_FLOORS);

            // counter of the number of objects
    int i=0;
    for (; i < 50; i++) 
        try {
            if (jsonFloors.getSlot(i) == null)
                break;
        } catch (JSException jse) {
            break;
        }

    Floor[] floors = new Floor[i];

    for (int t=0; t < i; t++) {

        JSObject jsonFloor = (JSObject) jsonFloors.getSlot(t);
        try {
            int numero_di_piano = Integer.parseInt(jsonFloor.getMember(NUMERO_DI_PIANO)+"");
            URL link = new URL(codebase, jsonFloor.getMember(LINK).toString());
            float bearing = Float.parseFloat(jsonFloor.getMember(BEARING).toString());
            int id = Integer.parseInt(jsonFloor.getMember(ID).toString());

            Floor floor = new Floor(numero_di_piano, link, bearing, id);
            floors[t] = floor;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }   
    }
    return floors;
}

The error CommunicationWithJS.java:75 is in

   int numero_di_piano = Integer.parseInt(jsonFloor.getMember(NUMERO_DI_PIANO)+"");

The value *NUMERO_DI_PIANO* returned from the server is an integer, I don't understand this strange behaviour.

EDIT:

I cross-tested the japplet with firefox and chrome, using some println. It comes out that the exception shows up only when I try to extract from the Json an int value. I succesfully extracted a double and a string.

On firefox the applet still working... On chrome 0 becames "0,000000" and 4 becomes "4,000000".

ADDITION

I solved the problem forcing the server to convert the integers in strings. But I don't think it's the correct way to work, it's a workaround. So, if somebody can come out with a valid answer, I will assign the points.

Upvotes: 0

Views: 864

Answers (1)

kiko
kiko

Reputation: 180

This is not a complete answer, but based on the error you are getting and the similar issue we're running into loading the website detailed in http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=647706 I believe the issue is related to the system locale. Is the system locale something different from en_US?

For a reason I haven't yet been able to understand, when running Java inside Firefox the locale does not influence the formatting methods, but on Chrome/Chromium it does, which leads to it generating locale-formatted floats ("0,0" instead of "0.0" in the Brazilian pt_BR locale, for instance) which Java can then not parse properly (presumably using a locale-independent conversion).

See also Problems using DecimalFormat

Upvotes: 1

Related Questions