I'm trying to login to smartsheet using their api but I'm encountering a NoClassDefFoundError caused by a ClassNotFound Exception.
import java.util.ArrayList;
import java.util.Properties;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.io.InputStream;
import java.io.FileInputStream;
import com.smartsheet.api.Smartsheet;
import com.smartsheet.api.SmartsheetFactory;
import com.smartsheet.api.models.Cell;
import com.smartsheet.api.models.Column;
import com.smartsheet.api.models.Row;
import com.smartsheet.api.models.Sheet;
import com.smartsheet.api.models.PagedResult;
import com.smartsheet.api.models.AutomationAction;
import com.google.gson.Gson;
import com.smartsheet.api.SmartsheetBuilder;
public class Main
{
//main method for our main class
public static void main(String args[]) throws Exception
{
/*line that throws error*/
Smartsheet ss = new SmartsheetBuilder().setAccessToken("myAccessToken").build();
// other parts of the program
return;
}
}
Stacktrace:
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonDeserializer at com.smartsheet.api.internal.SmartsheetImpl. (SmartsheetImpl.java:279) at com.smartsheet.api.SmartsheetBuilder.build(SmartsheetBuilder.java:258) at smartsheet.Main.main(Main.java:27) Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JsonDeserializer at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 3 more
Is there any particular reason why this error is thrown? I've tried to access smartsheet using smartsheetfactory as demonstrated in their sample program, but I'm getting the same error.
The reason why I got this error was because I had the wrong JAR file for the API in my build. The JsonSerializer class was a dependency, and the correct JAR file included dependencies.
NoClassDefFoundError
occurs when the class was present during Compile time but not available during Runtime for any reason.It is really hard to diagnose and fix this problem as the problem is unavailability of the class file at runtime in the classpath. Thy these point to solve the
NoClassDefFoundError
In J2EE environment it might be a case when one get
NoClassDefFoundError
even if the class is present because it may not be visible to the corresponding class loader.