2

I am working on an Android project that uses classes and methods from a seperate JAR file I am also creating, and the issue is with a specific util class called XpathUtil that is throwing a VerifyError every time I try calling one of its static methods.

Here is how my XpathUtil class looks like:

public class XpathUtil {

 private static XPath xpath = XPathFactory.newInstance().newXPath();
 private static String TAG = "XpathUtil";

 public static Document createXpathDocument(String xml) {
  try {

   Log.d(TAG , "about to create document builder factory");
   DocumentBuilderFactory docFactory = DocumentBuilderFactory
     .newInstance();
   Log.d(TAG , "about to create document builder ");
   DocumentBuilder builder = docFactory.newDocumentBuilder();

   Log.d(TAG , "about to create document with parsing the xml string which is: ");

   Log.d(TAG ,xml );
   Document document = builder.parse(new InputSource(
     new StringReader(xml)));

   Log.d(TAG , "If i see this message then everythings fine ");

   return document;
  } catch (Exception e) {
   e.printStackTrace();
   Log.d(TAG , "EXCEPTION OCCURED HERE " + e.toString());
   return null;
  }
 }

 public static NodeList getNodeList(Document doc, String expr) {
  try {
   Log.d(TAG , "inside getNodeList");
   XPathExpression pathExpr = xpath.compile(expr);
   return (NodeList) pathExpr.evaluate(doc, XPathConstants.NODESET);
  } catch (XPathExpressionException e) {
   e.printStackTrace();
  }
  return null;
 }

 // extracts the String value for the given expression
 public static String getNodeValue(Node n, String expr) {
  try {
   Log.d(TAG , "inside getNodeValue");
   XPathExpression pathExpr = xpath.compile(expr);
   return (String) pathExpr.evaluate(n, XPathConstants.STRING);
  } catch (XPathExpressionException e) {
   e.printStackTrace();
  }
  return null;
 }
}

And this is the exact line where the exception occurs from the main project I am working with:

mDocument = XpathUtil.createXpathDocument(xml);

As you can see, all I'm doing is simple calling createXpathDocument that is located from a seperate jar file that's been succesfully imported and included in my build path via eclipse (any other call I make to different classes from this jar works fine). So I'm not too sure what the issue is.

I tried doing a clean and build on both the main project and the other project I am using that I then export it to a actual jar file for third party apps to use, but for some strange reason this XpathUtil doesnt work.

edit: here is the exception:

Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
java.lang.RuntimeException: An error occured while executing doInBackground()
   at 

android.os.AsyncTask$3.done(AsyncTask.java:200)
   at 

java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)   at 

java.util.concurrent.FutureTask.setException(FutureTask.java:124)
    at 

java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
   at 

java.util.concurrent.FutureTask.run(FutureTask.java:137) at 

java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
 at 

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
  at 

java.lang.Thread.run(Thread.java:1096)
 Caused by: java.lang.VerifyError: 

com.kc.unity.agent.util.xml.XpathUtil    at com.kc.unity.agent.util.xml.ContactDescHelper.<init>

(ContactDescHelper.java:67)
   at 

com.kc.unity.agent.federation.contacts.ContactPlatformWrapper.constructContactDetails

(ContactPlatformWrapper.java:218)
  at 

com.kc.unity.agent.federation.contacts.ContactPlatformWrapper.getContactDetails

(ContactPlatformWrapper.java:101)    at 

com.kc.unified.contacts.ContactDetails.setContactFields(ContactDetails.java:154)   at com.kc.unified.contacts.ContactDetails.access$6

(ContactDetails.java:150)   at 

com.kc.unified.contacts.ContactDetails$LoadScreen.doInBackground(ContactDetails.java:79)
  at 

com.kc.unified.contacts.ContactDetails$LoadScreen.doInBackground(ContactDetails.java:1)
   at android.os.AsyncTask$2.call(AsyncTask.java:185)   at 

java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)... 4 more
Jono
  • 17,341
  • 48
  • 135
  • 217
  • 2
    It would be useful if you gave the actual text of the error including the stacktrace. There are several things that could cause `VerifyErrors` and at the moment it's impossible to do more than guess. – Andrzej Doyle Nov 05 '10 at 11:53
  • If you have the source of jar, could you try including the source instead of jar to main project to see whether the problem still exists? Just to make sure utility doesn't use something that is not supported in Android. – Suresh Nov 05 '10 at 11:56
  • That is how i had it setup Suresh, i first had the whole project added into the build path via going to eclipse > properties > java build path > projects. i will include the actual exception – Jono Nov 05 '10 at 12:04

2 Answers2

2

When I updata ADT tool to version 18.0.0.v201203301601-306762 I also get the exception when I run the app.... finally i found the solution with adt update issue. When you build the android app project, you need to go to project Properties-> Order and Export, and let the third party jar checkbox to be checked, and clean and rebuild the project. The problem would be fixed......for example let the third party jar checkbox to be checked

Jay Parker
  • 631
  • 11
  • 23
2

A typical scenario that leads to VerifyErrors: you have two different versions of a library, compile against version 1 and run with version 2. In that case, especially if method signatures have changed, the JVM might complain with a VerifyError.

So for your case: double check that you use the very same XPathUtil.class file for building and executing. Maybe the JVM has an old version of this class on the classpath (maybe it has even more than one versions and choose the wrong one).

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
  • maybe i can see what happens if i refactor and rename the XPathUtil class? as far as i know i dont have two versions of the library class i have implemented. just the one thats linked to my main project – Jono Nov 05 '10 at 13:22
  • @jonney - good idea. If you run with a old library, you might get a NoClassDefFoundError, if all errors are gone, then you had two entries of this class on the classpath. – Andreas Dolk Nov 05 '10 at 13:25
  • Nope it still diddnt work after refactoring the name of the class to include at s at the end of ot – Jono Nov 05 '10 at 14:12
  • 11-05 14:15:51.556: ERROR/AndroidRuntime(6233): Caused by: java.lang.VerifyError: com.kc.unity.agent.util.xml.XpathUtils – Jono Nov 05 '10 at 14:13
  • edit: i may have found the issue. i read before the varify error and noticed this 11-05 14:15:50.896: WARN/dalvikvm(6233): VFY: unable to resolve exception class 291 (Ljavax/xml/xpath/XPathExpressionException;) im going to remove XPathExpressionException and change it to just catch(Exception e) – Jono Nov 05 '10 at 14:16
  • That's not a solution but another hint: This Exception class was present during compilation (otherwise: compiletime error) and now it's not available at runtime. Something is wrong with you runtime classpath. – Andreas Dolk Nov 05 '10 at 14:22
  • right i tried changing it to Exception e and now i get this: 11-05 14:44:26.204: ERROR/AndroidRuntime(279): Caused by: java.lang.NoClassDefFoundError: javax.xml.xpath.XPathFactory – Jono Nov 05 '10 at 14:46
  • and 11-05 14:44:26.204: ERROR/AndroidRuntime(279): Caused by: java.lang.ExceptionInInitializerError – Jono Nov 05 '10 at 14:46