Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVEL2 on android throws exception

Tags:

android

mvel

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?

like image 460
user2379652 Avatar asked Jun 26 '13 11:06

user2379652


People also ask

How to throw exception with message?

Throwing an exception is as simple as using the "throw" statement. You then specify the Exception object you wish to throw. Every Exception includes a message which is a human-readable error description. It can often be related to problems with user input, server, backend, etc.

Which exception to throw java?

Only checked exceptions are required to be thrown using the throws keyword. Unchecked exceptions don't need to be thrown or handled explicitly in code.

How to call exception java?

You can throw an exception in Java by using the throw keyword. This action will cause an exception to be raised and will require the calling method to catch the exception or throw the exception to the next level in the call stack.

Can a class throw exception in java?

Classes cannot throw exceptions. Only methods may throw exceptions.

What is MVEL action execute?

MVELAction.execute (...) The MVEL convienence class is a collection of static methods that provides a set of easy integration points for MVEL. The vast majority of MVEL's core functionality can be directly accessed through methods in this class. Executes a compiled expression.

How do you throw an exception in Java?

In Java, all exception and error types are subclasses of Throwable. The Throwable class changes the execution flow of JVM apps by throwing exceptions and deciding how to recover from an error. For instance, the code below uses the throw statement to throw an IllegalStateException: .

How to handle all uncaught JVM exceptions?

Invoke the the default handler that handles all uncaught JVM exceptions by printing a stack trace report, and then terminating the app. The goal is to create an exception handler that captures the stack trace for every unhandled error, and generates a diagnostic report. Setting the UncaughtExceptionHandler as the default handler for all exceptions

How does the Java catch block handle exceptions?

Java catch block handles exceptions by declaring the exception type. The catch block comes after the try block. For example, the following code snippet handles throwables of type IllegalStateException


2 Answers

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!

like image 106
Izazael Avatar answered Nov 02 '22 23:11

Izazael


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

like image 31
Noam a Avatar answered Nov 03 '22 00:11

Noam a