Postingan

Menampilkan postingan dengan label error and exception

How to fix Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in Java

This error means your code or any external library you are using in your application is using the SLF4J library, an open source logging library, but it is not able to find the required JAR file e.g. slf4j-api-1.7.2.jar hence it's throwing Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory . If you look at the error, you will see that it's saying it is not able to find the class org/slf4j/LoggerFactory or org.slf4j.LoggerFactory. The package name indicates that it's part of SLF4j, hence you need SLF4j JAR files e.g. slf4j-api-1.7.2.jar in your application's classpath. So, go ahead and download the JAR file from SLFj website or from Maven Central repository and restart your application. Btw, the SLF4j is not really a logging API but it provides abstraction over other logging libraries e.g. Log4j, java.util.logging, or LogBak. It's similar to the commons-logging library but it doesn't mess up like that in a complex environm...

How to Solve UnrecognizedPropertyException: Unrecognized field, not marked as ignorable - JSON Parsing Error using Jackson

Gambar
While parsing JSON string received from one of our RESTful web services, I was getting this error "Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "person" (class Hello$Person), not marked as ignorable" . After some research, I found that this is one of the common error while parsing JSON document using Jackson open source library in Java application. The error messages say that it is not able to find a suitable property name called "person" in our case, let's first take a look at the JSON we are trying to parse, the class we are using to represent the JSON document and the error message itself. Error Message: Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "person" (class Hello$Person), not marked as ignorable (4 known properties: , "id", "city", "name", "phone...

How to deal with ConcurrentModificationException in Java? Beware while removing elements from ArrayList in loop

Gambar
One of the common problem while removing elements from an ArrayList in Java is the ConcurrentModificationException. If you use classical for loop with the index or enhanced for loop and try to remove an element from the ArrayList using remove() method, you will get the ConcurrentModificationException but if you use Iterator's remove method or ListIterator's remove() method, then you won't get this error and be able to remove the element. It's an unwritten rule in Java that while looping through the list, you should not add() or remove() elements until the collection supports fail-safe Iterator e.g. CopyOnWriteArrayList, which operate on a copy of list rather than the original list. The main problem with this error is that it confuses developer that list is getting modified by multiple threads and that's why Java is throwing this error, it's not true. Most of the time ConcurrentModificationException comes even without multiple threads modifying the list. It's...

How to deal with java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in Spring Application

Gambar
The java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet error comes when you deploy a Spring MVC application into Tomcat or Jetty and Servlet container not able to found this class, which usually found in the spring-webmvc.jar file. The DispatcherServlet is the core of Spring MVC framework, it implements the FrontController pattern and intercept all HTTP requests sent to your Web application and subsequently route it to correct controller based upon URL mapping. You need to declare the DispatcherServlet in your web.xml and specify the URL pattern so that Servlet container like Tomcat should send or route all HTTP request to the configured DispatcherServlet . We have also set load-on-startup tag as 1 for this Servlet so that it should be loaded at the deployment time, rather than at the response time when a call for this Servlet comes. In short, this DispatcherServlet is the link between the Servlet Container and Spring MVC framework. You can furthe...

How to fix invalid target release: 1.7, 1.8, 1.9, or 1.10 Error in Maven Build

Gambar
If you are building your Java project using Maven, maybe in Eclipse or from the command prompt by running mvn install and your build is failing with an error like "invalid target release: 1.7" or "invalid target release: 1.8" then you have come to the right place. In this article, I'll show you the reason why this error occurs and how you can deal with these errors even with higher Java version like Java 9, 10 installed on your machine, or maybe with Java 11 in the coming month. The root cause of the problem is that you have specified a higher Java version in your pom.xml file for Maven compiler plugin then what Maven knows in your system, and that's why it's saying invalid target release. A simple solution to this problem is either reduce your target version in pom.xml or install a new Java version if you want to build your project in higher version But, the key to solving this problem is knowing that Maven picks the Java version from the JAVA_HOME...

2 solution of java.lang.OutOfMemoryError in Java

Gambar
Everyone in java development faces java.lang.OutOfMemoryError now and then, OutOfMemoryError in Java is one problem which is more due to system's limitation (memory) rather than due to programming mistakes in most cases though in certain cases you could have a memory leak which causing OutOfMemoryError . I have found that even though java.lang.OutOfMemoryError is a quite common basic knowledge of its cause and the solution is largely unknown among junior developers. Beginners books like Head First Java doesn't teach you much about how to deal with this kind of error. You need real experience dealing with production systems, handling a large number of user sessions to troubleshoot and fix performance issues like running out of memory. If you want to be good at troubleshooting and performance analysis, you need to learn some books on Java performance and profiling e.g. Java Performance The Definitive Guide By Scott Oaks or the Java Performance by Binu John. They are an excellen...

Eclipse - java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in Tomcat

Gambar
Problem : You are getting java.lang.ClassNotFoundException exception complaining that Spring's DispatcherServlet class is not available in the classpath. This error is coming while running a Spring MVC based Java application from Eclipse and Tomcat as Server (running inside Eclipse IDE itself). You have either included spring framework JAR files manually by yourself or you are using Maven to download and manage dependent JAR files. Here is the stack trace of this error : java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507) at org.apache.catalina.core.DefaultInstanceManager.newInsta...

ORA-00904: invalid identifier Error in Oracle 11g database - Solved

Gambar
If you have worked in Oracle database ever, you would definitely have seen ORA-00904: invalid identifier error. Doesn't matter which version you are working 10g, 11g or 12g, this is one of the most common error comes while doing CRUD (Create, Read, Update, and Delete) operations in Oracle. By the way, if you are beginner, SELECT, INSERT, UPDATE and DELETE are used to perform CRUD operation in Oracle database. What do you do if you get this error while running in SQL script? Like any error, you should first pay attention to error message, what is Oracle trying to say here. Invalid identifier means the column name entered is either missing or invalid, this is one of the most common cause of this error but not the only one. Some time it come if you use names, which happened to be reserved word in Oracle database. Now how do you resolve it?  We will learn in this article, by following series of examples which first reproduce this error and later suggest how to fix it. In short, here is...

java.io.IOException: Map failed and java.lang.OutOfMemoryError: Map failed

Gambar
While working with memory mapped file, you may get java.io.IOException: Map failed error, which is mainly caused by Caused by: java.lang.OutOfMemoryError: Map failed error as shown below. This error usually comes while mapping a big file in memory e.g. trying to map a file greater than 1 or 2GB java.io.IOException: Map failed at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:888) Caused by: java.lang.OutOfMemoryError: Map failed at sun.nio.ch.FileChannelImpl.map0(Native Method) at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:885) ... 6 more How to Solve java.io.IOException: Map failed Depending upon which operating system you are working, e.g. Windows or UNIX, you can try different things to solve this error. One of the quick way to solve this by reducing size, which you want to map into memory. For example if you are trying to map 1GB into memory, you may want to only map 512MB or lower, if your code uses region based approach, this may work file. Alternatively you can a...