groovy compile error
- by Bunny Rabbit
class x{
public static void main(String[] args){
String x="<html><head></head></html>";
String arr[]=x.split("<head>");
String script="hi";
x=arr[0]+"<head>"+script+arr[1];
System.out.println(x);
}
}
the above code when compiled as a java file compiles fine but when used a s a groovy file spits the error :
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
D:\Garage\groovy-binary-1.7.1\groovy-1.7.1\bin\x.groovy: 4: Apparent variable 'a
rr' was found in a static scope but doesn't refer to a local variable, static fi
eld or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable fro
m a static context.
You misspelled a classname or statically imported field. Please check the spelli
ng.
You attempted to use a method 'arr' but left out brackets in a place not allowed
by the grammar.
@ line 4, column 10.
String arr[]=x.split("");
^
D:\Garage\groovy-binary-1.7.1\groovy-1.7.1\bin\x.groovy: 6: Apparent variable 'a
rr' was found in a static scope but doesn't refer to a local variable, static fi
eld or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable fro
m a static context.
You misspelled a classname or statically imported field. Please check the spelli
ng.
You attempted to use a method 'arr' but left out brackets in a place not allowed
by the grammar.
@ line 6, column 5.
x=arr[0]+""+script+arr[1];
^
D:\Garage\groovy-binary-1.7.1\groovy-1.7.1\bin\x.groovy: 6: Apparent variable 'a
rr' was found in a static scope but doesn't refer to a local variable, static fi
eld or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable fro
m a static context.
You misspelled a classname or statically imported field. Please check the spelli
ng.
You attempted to use a method 'arr' but left out brackets in a place not allowed
by the grammar.
@ line 6, column 28.
x=arr[0]+""+script+arr[1];
^
3 errors
D:\Garage\groovy-binary-1.7.1\groovy-1.7.1\bin