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.