“NoClassDefFoundError: Could not initialize class” error

When I run my project, I get numerous outputs of this error: Sep 9, 2009 8:22:23 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet Jersey threw exception java.lang.NoClassDefFoundError: Could not initialize class SpringFactory at com.point2.prospect.persistence.hibernate.HibernateTransactionInterceptor.doFilter(HibernateTrans actionInterceptor.java:17) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.point2.prospect.restapi.ServerErrorInterceptor.doFilter(ServerErrorInterceptor.java:27) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) … Read more

Why do I get an UnsupportedOperationException when trying to remove an element from a List?

Quite a few problems with your code: On Arrays.asList returning a fixed-size list From the API: Arrays.asList: Returns a fixed-size list backed by the specified array. You can’t add to it; you can’t remove from it. You can’t structurally modify the List. Fix Create a LinkedList, which supports faster remove. List<String> list = new LinkedList<String>(Arrays.asList(split)); On split taking regex From the API: String.split(String regex): Splits this string around … Read more

Why do I get “Exception; must be caught or declared to be thrown” when I try to compile my Java code?

All your problems derive from this byte[] encrypted = cipher.doFinal(toEncrypt.getBytes()); return encrypted; Which are enclosed in a try, catch block, the problem is that in case the program found an exception you are not returning anything. Put it like this (modify it as your program logic stands): public static byte[] encrypt(String toEncrypt) throws Exception{ try{ … Read more

What is difference between Errors and Exceptions?

An Error “indicates serious problems that a reasonable application should not try to catch.” while An Exception “indicates conditions that a reasonable application might want to catch.” Error along with RuntimeException & their subclasses are unchecked exceptions. All other Exception classes are checked exceptions. Checked exceptions are generally those from which a program can recover & it might be a good idea … Read more

How can I safely create a nested directory?

What is the most elegant way to check if the directory a file is going to be written to exists, and if not, create the directory using Python? Here is what I tried: import os file_path = “/my/directory/filename.txt” directory = os.path.dirname(file_path) try: os.stat(directory) except: os.mkdir(directory) f = file(filename) Somehow, I missed os.path.exists (thanks kanja, Blair, … Read more

Causes of getting a java.lang.VerifyError

java.lang.VerifyError can be the result when you have compiled against a different library than you are using at runtime. For example, this happened to me when trying to run a program that was compiled against Xerces 1, but Xerces 2 was found on the classpath. The required classes (in org.apache.* namespace) were found at runtime, so ClassNotFoundException was not the result. There … Read more

How to create a custom exception type in Java?

You should be able to create a custom exception class that extends the Exception class, for example: class WordContainsException extends Exception { // Parameterless Constructor public WordContainsException() {} // Constructor that accepts a message public WordContainsException(String message) { super(message); } } Usage: try { if(word.contains(” “)) { throw new WordContainsException(); } } catch(WordContainsException ex) { // Process … Read more