<br>I'm trying to use JDOM 1.1 on the Android 1.0 platform. <br><br>The Android platform supports most Java 5 API's. However, java.rmi.* classes are not part of the Android platform.<br><br>When I use JDOM 1.1 on Android, I see this error:<br>
<br><br>W/dalvikvm( 327): VFY: unable to resolve check-cast 98 (Ljava/rmi/RemoteException;) in Lorg/jdom/JDOMException;<br>W/dalvikvm( 327): VFY: rejecting opcode 0x1f at 0x003d<br>W/dalvikvm( 327): VFY: rejected Lorg/jdom/JDOMException;.getNestedException (Ljava/lang/Throwable;)Ljava/lang/Throwable;<br>
W/dalvikvm( 327): Verifier rejected class Lorg/jdom/JDOMException;<br>D/AndroidRuntime( 327): Shutting down VM<br>W/dalvikvm( 327): threadid=3: thread exiting with uncaught exception (group=0x40010e28)<br>E/AndroidRuntime( 327): Uncaught handler: thread main exiting due to uncaught exception<br>
E/AndroidRuntime( 327): java.lang.VerifyError: org.jdom.JDOMException<br><br><br>I looked at the JDOM source code and noticed that org.jdom.JDOMException uses java.rmi.RemoteException:<br><br> if (parent instanceof RemoteException) {<br>
return ((RemoteException)parent).detail;<br> }<br><br><br>In order for this code to run on Android, we would need to eliminate java.rmi.RemoteException from JDOMException.java<br><br>One possible fix (?) is to use reflection to retrieve the "detail" field:<br>
<br> if (parent.getClass().getName().startsWith("java.rmi.")) {<br> try {<br> Field f = parent.getClass().getField("detail");<br> return (Throwable) f.get(parent);<br>
} catch (Exception ignore) {<br> // ignored<br> }<br> }<br><br>Using 'startsWith' is a hack. The intent is to detect java.rmi.RemoteException as well as all <br>subclasses of java.rmi.RemoteException from the java.rmi pacakge.<br>
<br> <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/rmi/RemoteException.html" target="_blank">http://java.sun.com/j2se/1.4.2/docs/api/java/rmi/RemoteException.html</a><br><br>Is there a better way to code this? Any other comments? <br>
<br>Sean<br><br>