5

Did anyone has experience with MVEL2 on android?

i've tried out the same code with a simple java program and later on android:

The following exception is thrown when executed on android:

E/AndroidRuntime(30793): java.lang.ExceptionInInitializerError

I tried the example from the mvel website:

String template = "Hello, my name is @{name.toUpperCase()}";
Map vars = new HashMap();
vars.put("name", "Michael");
System.out.println(TemplateRuntime.eval(template, vars));

If theres no solution could anyone suggest a template engine which works with android and supports iteration?

2 Answers2

5

MVEL2 tries to substring the first 3 characters of the system java.version property when initializing the parser, and under Android the version is 0. That causes a bunch of exceptions which eventually cause the ExceptionInInitializerError.

If you want to force the java.version property, you can simply set it yourself:

System.setProperty("java.version", "1.6");

I have no idea what kind of odd side effects this may cause for Android, but at least it gets the MVEL parser up and running without throwing exceptions!

Izazael
  • 171
  • 3
  • 2
    If you are worried about side-effects, try reseting the property back. Like this. `String javaVersion = System.getProperty("java.version"); System.setProperty("java.version", "1.6"); doCodeHere();System.setProperty("java.version", javaVersion);` – Kayla Feb 07 '14 at 22:04
1

System.setProperty with "java.version" key seems to be read only propery in android, so it won't work. i've tried to integrate MVEL 2 into android with no success, try using EVAL lib

Noam a
  • 199
  • 1
  • 6