[jdom-interest] using JDOM 1.1 on Android's Dalvik VM
Laurent Bihanic
laurent.bihanic at atosorigin.com
Wed Nov 26 13:27:59 PST 2008
Hi,
> Is there a better way to code this? Any other comments?
Seems OK but you may wish to stick to the existing way of handling possibly
not available exception classes in JDOMException by :
- adding a new getNestedException() method e.g.
getNestedExceptionFromField(Throwable, String, String)
- using Class.forName() and isAssignableFrom as in :
Class testClass = Class.forName(className);
Class objectClass = parent.getClass();
if (testClass.isAssignableFrom(objectClass)) {
...
Laurent
Sean Sullivan wrote:
>
> I'm trying to use JDOM 1.1 on the Android 1.0 platform.
>
> The Android platform supports most Java 5 API's. However, java.rmi.*
> classes are not part of the Android platform.
>
> When I use JDOM 1.1 on Android, I see this error:
>
>
> W/dalvikvm( 327): VFY: unable to resolve check-cast 98
> (Ljava/rmi/RemoteException;) in Lorg/jdom/JDOMException;
> W/dalvikvm( 327): VFY: rejecting opcode 0x1f at 0x003d
> W/dalvikvm( 327): VFY: rejected
> Lorg/jdom/JDOMException;.getNestedException
> (Ljava/lang/Throwable;)Ljava/lang/Throwable;
> W/dalvikvm( 327): Verifier rejected class Lorg/jdom/JDOMException;
> D/AndroidRuntime( 327): Shutting down VM
> W/dalvikvm( 327): threadid=3: thread exiting with uncaught exception
> (group=0x40010e28)
> E/AndroidRuntime( 327): Uncaught handler: thread main exiting due to
> uncaught exception
> E/AndroidRuntime( 327): java.lang.VerifyError: org.jdom.JDOMException
>
>
> I looked at the JDOM source code and noticed that org.jdom.JDOMException
> uses java.rmi.RemoteException:
>
> if (parent instanceof RemoteException) {
> return ((RemoteException)parent).detail;
> }
>
>
> In order for this code to run on Android, we would need to eliminate
> java.rmi.RemoteException from JDOMException.java
>
> One possible fix (?) is to use reflection to retrieve the "detail" field:
>
> if (parent.getClass().getName().startsWith("java.rmi.")) {
> try {
> Field f = parent.getClass().getField("detail");
> return (Throwable) f.get(parent);
> } catch (Exception ignore) {
> // ignored
> }
> }
>
> Using 'startsWith' is a hack. The intent is to detect
> java.rmi.RemoteException as well as all
> subclasses of java.rmi.RemoteException from the java.rmi pacakge.
>
> http://java.sun.com/j2se/1.4.2/docs/api/java/rmi/RemoteException.html
>
> Is there a better way to code this? Any other comments?
>
> Sean
More information about the jdom-interest
mailing list