Java. Lang. noclassdeffounderror Error

Source: Internet
Author: User

ApplicationProgramWhen I ran, I suddenly reported caused by: Java. lang. noclassdeffounderror: cocould not initialize class COM. xxx. xxx. xxx error. The first response was. noclassdeffounderror, it must be that the class cannot be found. So hurry up.CodeIt is confusing to find that there are no compilation errors in calling the class. Why is there a noclassdeffounderror error. After re-Compiling and checking it again, the same error is still reported, so the following error message attracts attention [cocould not initialize ].

 

It cannot be initialized, that is, the class encountered a problem when it was new. So I checked the class that could not be initialized carefully and found that it was a static tool class, and there was no constructor at all, so there is no constructor. Why is the initialization exception? So after carefully checking the code, we found that the exception may occur in this place.

 Static{Inputstream in= Xxx.Class. Getresourceasstream ("/CONF/ABC. properties");Try{Prop. Load (in );}Catch(Ioexception e) {e. printstacktrace ();}}

The key is the inputstream in = xxx in the first line. class. getresourceasstream ("/CONF/ABC. properties ");, if ABC. properties, an exception will occur, which will cause initialization errors. Of course, it is strange that, since try, why not put the first line of code in try? In this way, even if there is an error, initialization will be smooth.

The solution is to add ABC. properties in step 1. The key is step 2. Put all the code in try. The key of step 2 lies in the overall requirements of the business and the overall requirements of the design. Whether to put them in the room requires comprehensive consideration, but the premise is that you need to be aware of this, instead of simply adding an ABC. properties. This kind of consciousness is an obvious sign of distinguishing between junior and intermediate programmers.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.