java.lang.NoClassDefFoundError: 无法初始化类 com.google.api.client.util.Data

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25011108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:26:17  来源:igfitidea点击:

java.lang.NoClassDefFoundError: Could not initialize class com.google.api.client.util.Data

javanoclassdeffounderror

提问by user3886610

When I programming, an error occured:

当我编程时,出现错误:

"java.lang.NoClassDefFoundError: Could not initialize class com.google.api.client.util.Data"

How to resolve it?

如何解决?

采纳答案by Deepanshu J bedi

The ways to resolve the java.lang.NoClassDefFoundError are :- Follow the link.

解决 java.lang.NoClassDefFoundError 的方法是:- 按照链接。

What is reason of NoClassDefFoundError in Java?

Java 中 NoClassDefFoundError 的原因是什么?

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time. For example if we have a method call from a class or accessing any static member of a Class and that class is not available during run-time then JVM will throw NoClassDefFoundError. It's important to understand that this is different than ClassNotFoundException which comes while trying to load a class at run-time only and name was provided during runtime not on compile time. Many Java developer mingle this two Error and gets confused.

In short NoClassDefFoundError will come if a class was present during compile time but not available in java classpath during runtime. Normally you will see below line in log when you get NoClassDefFoundError:

当 Java 虚拟机无法在运行时找到在编译时可用的特定类时,就会出现 Java 中的 NoClassDefFoundError。例如,如果我们有一个来自类的方法调用或访问类的任何静态成员,并且该类在运行时不可用,那么 JVM 将抛出 NoClassDefFoundError。重要的是要了解这与 ClassNotFoundException 不同,后者仅在运行时尝试加载类时出现,并且名称是在运行时而非编译时提供的。许多 Java 开发人员混淆了这两个错误并感到困惑。

简而言之,如果类在编译时存在但在运行时在 java 类路径中不可用,则会出现 NoClassDefFoundError。通常,当您收到 NoClassDefFoundError 时,您会在日志中看到以下行:

How to resolve java.lang.NoClassDefFoundError:

如何解决 java.lang. NoClassDefFoundError

  1. Class is not available in Java Classpath.
  2. You might be running your program using jar command and class was not defined in manifest file's ClassPath attribute.
  3. Any start-up script is overriding Classpath environment variable.
  4. Because NoClassDefFoundError is a sub class of java.lang.LinkageError it can also come if one of it dependency like native library may not available.
  5. Check for java.lang.ExceptionInInitializerError in your log file. NoClassDefFoundError due to failure of static initialization is quite common.
  6. If you are working in J2EE environment than visibility of Class among multiple Classloaders can also cause java.lang.NoClassDefFoundError, see examples and scenario section for detailed discussion.
  1. 类在 Java 类路径中不可用。
  2. 您可能正在使用 jar 命令运行您的程序,并且清单文件的 ClassPath 属性中未定义类。
  3. 任何启动脚本都会覆盖 Classpath 环境变量。
  4. 因为 NoClassDefFoundError 是 java.lang.LinkageError 的子类,如果其中一个依赖项(如本机库)不可用,它也会出现。
  5. 检查日志文件中的 java.lang.ExceptionInInitializerError 。由于静态初始化失败而导致的 NoClassDefFoundError 很常见。
  6. 如果您在 J2EE 环境中工作,多个 Classloader 之间 Class 的可见性也会导致 java.lang.NoClassDefFoundError,请参阅示例和场景部分进行详细讨论。

回答by Tobi Nonymous

You or some code you have imported into your project seems to refer to the Google Data Client API, but you didn't import the necessary .jar file into your projects dependencies.

您或您导入到项目中的某些代码似乎引用了 Google 数据客户端 API,但您没有将必要的 .jar 文件导入到您的项目依赖项中。

Try copying this jar into your project: https://code.google.com/p/gdata-java-client/downloads/list?hl=de

尝试将此 jar 复制到您的项目中:https: //code.google.com/p/gdata-java-client/downloads/list?hl=de

Maybe the setup instructions here also are interesting for you: https://developers.google.com/gdata/articles/java_client_lib?hl=de#gdata

也许这里的设置说明对您来说也很有趣:https: //developers.google.com/gdata/articles/java_client_lib?hl=de#gdata