Getting "Missing ; before statement" error

Posted by bjorn_kroghrud on 10-Dec-2009 14:56

Hi,

I am trying the following code in a javascript rule file:

function rule()
{
    java.lang.System.out.println("num parts: " + XQMessage.getPartCount()); 
    java.lang.String sContentType = XQMessage.getPart(0).getContentType();
    return null;
}

I keep getting "JavaScript Error: Internal Error: SyntaxError: missing ;
before statement (line 4)". I cannot see anything wrong with getPart(0)
as getPartCount() returns 1. Am I missing something here?

All Replies

Posted by Matt Baker on 10-Dec-2009 17:50

You appear to be mixing javascript and java.

This is a javascript function definition:

function rule()...

This is a java function call

java.lang.System.out.println...

which language are you trying to use?

Posted by bjorn_kroghrud on 11-Dec-2009 01:35


Yes, these are java calls, but they should work.
If I remove the statement:
"java.lang.String sContentType = XQMessage.getPart(0).getContentType();"
there is no error and I see output from "java.lang.System.out.println(...".



Posted by Bill Wood on 11-Dec-2009 19:10

One comment --- you can certainly use Java objects from inside JavaScript -- and you seem to be doing that correctly (i.e. you preface the method with the explicit class), so this is perfectly fine.

function rule()
{  
        java.lang.System.out.println("Testing calls to Java in Javascript" );
        return null;

}

Looking at your code it seems fine -- but the real interpreter is probably seeing something I can't.  I might remove the java.lang.String from line 3, and just use JavaScripts automatic type converion.  You definitely don't need that, however, I do not think that is the issue.

All I can recomment is removing all the lines and starting from scratch adding them in one-by-one.

I am guessing this works

function rule() 
{
    java.lang.System.out.println("num parts: " + XQMessage.getPartCount()); 
    return null;
}

// So try adding:
   sContentType = XQMessage;
// and then:
   sContentType = XQMessage.getPart(0);
// and then:
   sContentType = XQMessage.getPart(0).getContentType();




Posted by bjorn_kroghrud on 14-Dec-2009 11:59

Of course. This is Javascript and does not need class specification.

Removing java.lang.String. did the trick.

Thanks!

Posted by Bill Wood on 16-Dec-2009 12:54

Glad it worked.  In thinking about it, the casting of objects definitely is the problem.   You can refer to Java static objects and classes using the fully qualified packages, so that is why you need java.lang.System.out.println ("something") but you don't use the typing for assignments.

This thread is closed