NullPointerException when upgrading Marvin 5.1.4 to 5.2.6

User dfeb81947d

15-12-2009 13:46:23

Dear support,

In a JSP I have a javascript object that allow a
user to use wheter the awt marvin sketcher, whether the swing version.
The code is detailed below.

When changing a version of marvin I
always do as so: erase the folder "chemaxon" from the ancient version
and copy the new one from the package installed after downloading the
last version.

Last version I had was Marvin 5.1.4, and I wanted to upgrade to 5.2.6.

So
I completly delete the directory of marvin 5.1.4 and replace with the
directory of marvin 5.2.6. I remove java cache which is jdk1.5.

But when I start the JSP home page, I got a NullPointerException on : "this.setMolfile = function(molfile)".
The
attribute setMolfile is used to load a default molecule (aspirin) to
check wether the sketcher is working and is loaded or not.
the tag body of the jsp page contain a method onLoad which test if the browser is okay.

With
Marvin 5.1.4 everything works fine, but with Marvin 5.2.6 it seems that
when calling the method to test if the sketcher is properly installed
and loaded, actually he hasn't been initialized.

It happens
while using jdk 1.6.0_15 but knowing about problem with cache in this
version of jdk and marvin, I tried also with jdk 1.5.0_18.

Is there major change in Marvin 5.2.6 in the way he is loaded?
Knowing
the difference between 5.1.4 and 5.2.6, where could be the problem? I'm
looking for a solution for a few day (another solution than downgrading
Marvin to 5.1.4), and haven't found yet.
Any hint would help a lot.

Thank you very much for the help and advices.

Best Regards,
Jacques


if (!AP_Objects) {var AP_Objects = new Array();}
function MoleculeViewer(id) {
    this.id;
    this.viewerType=0;
    this.viewerWidth=460;
    this.viewerHeight=340;
    this.viewerColor="#FFF5DE";

        
    this._constructor = function(id) {
        this.id=id;
        AP_Objects[this.id] = this;
    }
    
    this.draw = function() {
        var content = document.writeln(this.toHtml());
    }
    
    this.toHtml = function() {
        switch (this.viewerType) {
            case 0:
                marvin_jvm="builtin";
                marvin_gui = "awt";
                msketch_name = this.id;
                return msketch_begin("/TomcatApp/marvin/",this.viewerWidth,this.viewerHeight)+
                    msketch_param("molbg",this.viewerColor)+
                    msketch_param("background",this.viewerColor)+
                    msketch_param("undo","10")+
                    msketch_param("reactionSupport","false")+
                    msketch_param("preload", "MolExport")+
                    //msketch_param("detach", "hide")+
                    
                    msketch_param("menubar","true")+
                    msketch_param("buttonmenubar","false")+
                    msketch_param("detach","hide")+
                    msketch_param("undetachByX","false")+
                    msketch_end();
            case 1:
                marvin_jvm="builtin";
                marvin_gui = "swing";
                msketch_name = this.id;
                return msketch_begin("/TomcatApp/marvin/",this.viewerWidth,this.viewerHeight)+
                    msketch_param("molbg",this.viewerColor)+
                    msketch_param("background",this.viewerColor)+
                    msketch_param("undo","10")+
                    msketch_param("reactionSupport","false")+
                    msketch_param("preload", "MolExport")+
                    //msketch_param("detach", "hide")+
                    //msketch_param("menubar", "false")+
                    
                    msketch_param("menubar","true")+
                    msketch_param("buttonmenubar","false")+
                    msketch_param("detach","hide")+
                    msketch_param("undetachByX","false")+
                    
                    msketch_end();
            default:
                return 'Error: Unknown viewer.';
        }
    }
    
    // Gets the currently displayed molecule as molfile
    this.getMolfile = function() {
        if (this.isEmpty()) {
            return "";
        }
        switch (this.viewerType) {
            case 0:
                return document.getElementById(this.id).getMol("mol");
            case 1:
                return document.getElementById(this.id).getMol("mol");
        }
    }
    
    // Sets the molecule in the viewer
    this.setMolfile = function(molfile) {
        try {
            switch (this.viewerType) {
                case 0:
                    if (molfile!="") {
                        document.getElementById(this.id).setMol(molfile);
                    }
                    else {
                       
document.getElementById(this.id).setMol("\n  -ISIS-  06090416142D\n\n 
0  0  0  0  0  0  0  0  0  0999 V2000\nM  END\n");
                    }
                    break;
                case 1:
                    if (molfile!="") {
                        document.getElementById(this.id).setMol(molfile);
                    }
                    else {
                       
document.getElementById(this.id).setMol("\n  -ISIS-  06090416142D\n\n 
0  0  0  0  0  0  0  0  0  0999 V2000\nM  END\n");
                    }
                    break;

        }
        catch(excep) {
           
alert("The molecule viewer failed to initialize. Please check the
prerequisites for this viewer on the 'Home' tab, or contact
support."+e.name+", "+e.message);
        }
    }
    
    // Checks if the viewer contains a molecule
    this.isEmpty = function() {
        var ret=false;
        switch (this.viewerType) {
            case 0:
                ret=document.getElementById(this.id).isEmpty();
                break
            case 1:
                ret=document.getElementById(this.id).isEmpty();
                break

        return ret;
    }
    
    this.reset = function() {
        this.setMolfile("");
    }
        
    this._constructor(id);
}


ChemAxon 7c2d26e5cf

15-12-2009 23:30:14

Some parts of your comment is not clear for me.


I do not understand how you can provide AWT applet for your users in Marvin 5.1.4 since we have stopped support of AWT version of Marvin applets at Marvin 5.0.


Probably, your users use Marvin 4.0.6 (it was the last version that still supported AWT applet).


I assume that the reference to the deprecated elements causes the problem: "marvin_jvm=builtin" and "marvin_gui=awt"


I recommend to remove making differences between awt and swing from your applet example and use default settings.


Furthermore, I do not understand why you use



return msketch_begin("/TomcatApp/marvin/",this.viewerWidth,this.viewerHeight)+
                    msketch_param("molbg",this.viewerColor)+


such kind of statements in your code. marvin.js generates the applet code with the following methods:


msketch_begin(...)
msketch_param(...)
msketch_end(...)


The first two method writes into a buffer, the last one assign closing tag to the buffer and write result ino the current document: document.write(s). Because of it, I guess that checking the return value of these methods are irelevant.


By the way, there were a lot of changes between 5.1 and 5.2. You can find more details in Marvin documentation:


http://www.chemaxon.com/marvin/help/developer/changes.html

User dfeb81947d

16-12-2009 09:06:11

Thank you very much for your answer. I will follow your advices.


The presence of Marvin awt and those strange call to javascript are historical I guess... The code has not been changed since the first versions of Marvin applet.

User dfeb81947d

16-12-2009 10:48:14

Dear Tamas,


I replace the javascript call with html code (applet tag)




return '<applet id="'+this.id+'" name="'+this.id+'" codebase="/TomcatApp/marvin/" code="JMSketch.class" archive="jmarvin.jar"'+
                ' width="'+this.viewerWidth+'" height="'+this.viewerHeight+'">'+
                '<param name="molbg" value="'+this.viewerColor+'">'+
                '<param name="background" value="'+this.viewerColor+'">'+
                '<param name="undo" value="10">'+
                '<param name="reactionSupport" value="false">'+
                '<param name="preload" value="MolExport">'+
                '<param name="menubar" value="true">'+
                '<param name="buttonmenubar" value="false">'+
                '<param name="detach" value="hide">'+
                '<param name="undetachByX" value="false">'+
                '<strong>Your browser does not support the applet tag.</strong>'+
                '</applet>';

And everything works perfectly.


Thank you very much again for your explanation and advices.