【问题标题】:java.lang.VerifyErrorjava.lang.VerifyError
【发布时间】:2011-05-05 13:40:56
【问题描述】:

我正在开发一个 Android 项目,该项目使用我也在创建的单独 JAR 文件中的类和方法,问题在于一个名为 XpathUtil 的特定实用程序类,每次我尝试调用时都会抛出 VerifyError它的静态方法之一。

这是我的 XpathUtil 类的样子:

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;
 }
}

这正是我正在处理的主项目中发生异常的确切行:

mDocument = XpathUtil.createXpathDocument(xml);

如您所见,我所做的只是简单地调用createXpathDocument,它位于一个单独的 jar 文件中,该文件已通过 eclipse 成功导入并包含在我的构建路径中(我对不同类的任何其他调用) jar 工作正常)。所以我不太确定问题是什么。

我尝试在主项目和我正在使用的另一个项目上进行清理和构建,然后将其导出到实际的 jar 文件以供第三方应用程序使用,但由于某些奇怪的原因,此 XpathUtil 不起作用。

编辑:这是一个例外:

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

【问题讨论】:

  • 如果您提供错误的实际文本(包括堆栈跟踪),这将很有用。有几件事可能会导致VerifyErrors,目前除了猜测之外不可能做更多的事情。
  • 如果你有jar的源代码,你可以尝试将源代码而不是jar包含到主项目中,看看问题是否仍然存在?只是为了确保实用程序不使用 Android 不支持的东西。
  • 这就是我设置 Suresh 的方式,我首先通过 eclipse > 属性 > java 构建路径 > 项目将整个项目添加到构建路径中。我将包括实际的例外情况

标签: java android xpath


【解决方案1】:

导致 VerifyErrors 的典型场景:您有两个不同版本的库,针对版本 1 进行编译并使用版本 2 运行。在这种情况下,特别是如果方法签名已更改,JVM 可能会抱怨 VerifyError .

因此,对于您的情况:仔细检查您是否使用相同的 XPathUtil.class 文件进行构建和执行。可能 JVM 在类路径上有这个类的旧版本(可能它甚至有多个版本并选择了错误的版本)。

【讨论】:

  • 也许我可以看到如果我重构并重命名 XPathUtil 类会发生什么?据我所知,我没有实现的库类的两个版本。只是与我的主要项目相关联的那个
  • @jonney - 好主意。如果您使用旧库运行,您可能会收到 NoClassDefFoundError,如果所有错误都消失了,那么您在类路径上有两个此类的条目。
  • 不,在重构类的名称以包含在 ot 末尾的 s 之后它仍然没有工作
  • 11-05 14:15:51.556: ERROR/AndroidRuntime(6233): Caused by: java.lang.VerifyError: com.kc.unity.agent.util.xml.XpathUtils
  • 编辑:我可能发现了问题。我在 varify 错误之前阅读并注意到这个 11-05 14:15:50.896: WARN/dalvikvm(6233): VFY: unable to resolve exception class 291 (Ljavax/xml/xpath/XPathExpressionException;) 我要删除 XPathExpressionException 并更改它只是捕获(异常 e)
【解决方案2】:

当我将 ADT 工具更新到版本 18.0.0.v201203301601-306762 当我运行应用程序时,我也遇到了异常...... 最后我找到了 adt 更新问题的解决方案。 构建android app项目时,需要进入项目Properties->Order and Export,勾选第三方jar复选框,清理并重建项目。 问题将得到解决......for example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-05
    • 2018-09-22
    • 2010-10-14
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多