Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32368
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Nigel Wade <nmw@ion.le.ac.uk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: What is NoClassDefFoundError? And what is ClassNotFoundException? |
| Date | Wed, 19 Aug 2015 17:50:11 +0100 |
| Lines | 48 |
| Message-ID | <d3jqe3Fd7haU1@mid.individual.net> (permalink) |
| References | <8d073a5a-b5a8-463a-8003-5eb743bad5c8@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net GOE0kKwZdt8gunQBX+Vf9wP8rfV5EiRpTl+vhmkMlZe84aDipL |
| Cancel-Lock | sha1:u/6KtAYHMmtlmQWIv9Aaa/A5iTk= |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 |
| In-Reply-To | <8d073a5a-b5a8-463a-8003-5eb743bad5c8@googlegroups.com> |
| Xref | csiph.com comp.lang.java.programmer:32368 |
Show key headers only | View raw
On 19/08/15 17:06, John wrote:
> I am reading an article listed at the top for this topic by Google:
>
> [QUOTE]
> 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.
> [/QUOTE]
>
>
> If my English serves me OK, I don't see the difference between the two decribed by the author: when compiling the program, all the classes are available. However, (maybe delivered to somebody), when running the program, certain class is not available (or cannot be found, ie, not in the classpath). Correct?
>
> Thank you.
>
Unfortunately, that explanation is very poor. The JVM API explains it better than random pages courtesy of Google.
NoClassDefFoundError:
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a
normal method call or as part of creating a new instance using the new expression) and no definition of the class could
be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no
longer be found.
ClassNotFoundException:
Thrown when an application tries to load in a class through its string name using:
The forName method in class Class.
The findSystemClass method in class ClassLoader .
The loadClass method in class ClassLoader.
but no definition for the class with the specified name could be found.
]
NoClassDefFoundError is thrown by the JVM, or a ClassLoader, if the JVM/ClassLoader is unable to find a class at runtime
which was available when the current class was compiled. The run-time linkage is broken.
ClassNotFoundException will be thrown if using reflection, and an attempt is made to locate, load or otherwise access a
class by name and it cannot be located. In this case the class cannot be searched for at compile time because its name
isn't known until runtime.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
What is NoClassDefFoundError? And what is ClassNotFoundException? John <xsli2@yahoo.com> - 2015-08-19 09:06 -0700 Re: What is NoClassDefFoundError? And what is ClassNotFoundException? Nigel Wade <nmw@ion.le.ac.uk> - 2015-08-19 17:50 +0100
csiph-web