Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

android - java.lang.VerifyError

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...