Posts

Showing posts with the label error and exception

"The system cannot find the path specified." Error in Command Prompt

Recently I was trying to run the Apache Tomcat server from the command prompt to test my Java web application on localhost, only to find the "The system cannot find the path specified" error in command prompt. I haven't seen this error before so I was wondering whether tomcat is throwing or something is wrong with my system's PATH environment variable . In order to start the tomcat server, I was running the catalina.bat file as tomcat/bin/catalina.bat start and it wasn't starting the Tomcat at all, instead, it was keep throwing "The system cannot find the path specified." error as shown below: Read more �

Exception in thread "main" java.lang.NoClassDefFoundError: Running Java from Command line

The "Exception in thread "main" java.lang.NoClassDefFoundError: helloworldapp/HelloWorldApp" error comes when you are trying to run the HelloWorldApp Java program from the command line but either .class file is not there or Java is not able to find the class file due to incorrect classpath settings. The name of the class could be different in each case, it depends upon which class you are passing to java command for running from the command prompt. Another interesting thing to remember is that this error only comes in Java version less than or equal to Java 6 e.g. Java 1.5 or Java 1.4, if you are running in JDK 7 or Java 8 instead of this you will see "Error: could not able to find or load class HelloWorldApp" . Technically, both errors come due to same reason and their solution is also exactly same. Read more �

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

If you are working in Java web or enterprise application which connect to any other web server using HTTPs you might have seen the " javax.net.ssl.SSLHandshakeException" . This is one of the particular case of that error. If you know how SSL and HTTPS works that when a Java client connect to a Java server the SSL handshake happens. In this steps server return certificates to confirm it's identity, which then client validates against the root certificate he has in its truststore . If Server return a certificate which cannot be validated against the certificates a browser or Java client holds in its truststore then it throws the "sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target". Read more �

How to increase heap size of Eclipse - Solving OutOfMemoryError

If you are running lots of Java projects in Eclipse and it's throwing OutOfMemoryError every now and then it's time to increase the heap memory of Eclipse. Since Eclipse is a Java program, you can increase heap size of Eclipse by using JVM memory options -Xms and -Xmx. There are two ways to provide JVM options to eclipse either updating Eclipse shortcut or adding -vmargs on eclipse.ini file. I prefer the second option because it's clean. I'll tell you the exact steps to increase the java heap space in Eclipse but before that some background why I had to increase heap memory of Eclipse. I was getting "an internal error occurred during repository search . java heap space" while using Maven in Eclipse. Eclipse keep throwing java.lang.OutOfMemory:Java Heap Space while updating the index or searching for maven artifacts. Read more �

Tutorial to Solve "No JVM installation found ( Please install a 64-bit JDK )

Image
To start with you have installed Android Studio, which is the official Integrated Development Environment (IDE) for Android app development, based on IntelliJ IDEA, but as soon as you click on the Android Studio Desktop Icon to start Android Studio you are getting "No JVM installation found. Please install a 64-bit JDK" error? How do you solve this problem? Well, even though the error message is same, every problem is different depending upon your machine, the Java version, whether your desktop or laptop has 32-bit or 64-bit OS e.g. Windows 8.1 or Windows 10. Whether you have installed 32-bit Java or 64-bit JDK e.g. JDK 1.8.0 and what is the value of JAVA_HOME environment variable or whether you have defined it or not. I'll go through a couple of examples to solve "No JVM installation found. Please install a 64-bit JDK" error based upon some common scenarios. Most likely you would be able to solve your problem by following these steps, but if you are not the...

2 Reasons of org.springframework.beans.factory.BeanCreationException: Error creating bean with name [Solution]

The Spring framework is one of the most popular frameworks for developing Java application. Apart from many goodies, it also provides a DI and IOC container which initialize objects and their dependencies and assemble them together. The Java classes created and maintained by Spring are called Spring bean . At the startup, when Spring framework initializes system by creating objects and their dependencies depending upon @Autowired annotation or spring configuration XML file, it throws "org.springframework.beans.factory.BeanCreationException: Error creating a bean with name X" error if it is not able to instantiate a particular Spring bean. There could be numerous reasons why Spring could not able to create a bean with name X, but clue always lies on the detailed stack trace. This error always has some underlying cause e.g. a ClassNotFoundException or a NoClassDefFoundError , which potentially signal a missing JAR file in the classpath. Read more �

How to solve java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test

The error "java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test" occurs when you try to connect MySQL database running on your localhost, listening on port 3306 port from Java program but either you don't have MySQL JDBC driver in your classpath or driver is not registered before calling the getConnection() method. Since JDBC API is part of JDK itself, when you write a Java program to connect any database like MySQL, SQL Server or Oracle, everything compiles fine, as you only use classes from JDK but at runtime, when the JDBC driver which is required to connect to database is not available, JDBC API either throws this error or "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" . Read more �

java.lang.numberformatexception for input string null - Cause and Solution

The java.lang.NumberFormatException comes when you try to parse a non-numeric String to Number e.g. Short , Integer , Float , Double etc. For example, if you try to convert . "null" to an integer then you will get NumberFormatException. The error "Exception in thread "main" java.lang.NumberFormatException: For input string: "null" is specifically saying that the String you receive for parsing is not numeric and it's true, "null" is not numeric. Many Java methods which convert String to numeric type e.g. Integer.parseInt() which convert String to int , Double.parseDoble() which convert String to double , and Long.parseLong() which convert String to long throws NumberFormatException to inform that the input String is not numeric. Read more �

Maven Eclipse Error - "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK"

Image
If you are like many Java developer who uses Maven and Eclipse to build Java project using M2Eclipse plugin, you might have seen this error before. I ran into it recently when I ran the Maven Install command for one of the Java projects, configured as Maen project, only to realize that Maven builds failed after throwing this error. The main reason for this error is that Maven is not able to find javac (the Java compiler) which is required to compile Java source file. If you remember, the javac command comes in the bin directory of JDK, hence, you need a JDK installation in your local machine to compile Java project. You also need to have that configured in Eclipse as Installed JRE. Most likely, you have only installed and set up JRE and not JDK, at least that was the reason it throws "No compiler is provided in this environment" in my machine. Tools and Environment JDK 1.8 Eclipse Kepler M2Eclipse Apache Maven 3.0.3 I had a Java project configured as Maven project and th...

Minecraft - java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied Solution

You can resolve java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied error in Minecraft by disabling your anti-virus and run. Later you can whitelist the lwjgl64.dll, so that your anti-virus will not block it again. I have talked about java.lang.UnsatisfiedLinkError couple of times on this blog e.g. here and here . But, today I am going to show you one more real life example of java.lang.UnsatisfiedLinkError , which is more interesting. We'll also learn and how to deal with that. This problem is related to Minecraft , one of the most popular game written in Java. Precisely, we are going to solve the "Exception in thread "main" java.lang.UnsatisfiedLinkError: lwjgl64.dll: Access denied" error. Read more �

3 Ways to Solve jQuery - Uncaught ReferenceError: $ is not defined Error

If you are using jQuery, Angualr JS or plain old JavaScript and getting "Uncaught ReferenceError: $ is not defined" error which means $ is either a variable or a method which you are trying to use before declaring it using var keyword. In jQuery, it's a short name of jQuery() function and most commonly used in $(document).ready(function()) . If you are doing some jQuery stuff when DOM is loaded and getting this error it means your browser has a problem loading jQuery library either from the internet or local file system. In this article, you will see some of the most common reasons of "Uncaught ReferenceError: $ is not defined" error and how to solve them, but before that let's learn some basic about the dreaded Uncaught ReferenceError: $ is not defined error. Read more �

10 Exception handling Best Practices in Java Programming

Exception handling is an important part of writing robust Java application. It�s a non functional requirement for any application, to gracefully handle any erroneous condition like resource not available, invalid input, null input and so on. Java provides several exception handling features, in built in language itself in form of try , catch an d finally keyword . Java programming language also allows you to create new exceptions and throw them using throw and throws k eyword. In reality, Exception handling is more than knowing syntax. Writing a robust code is an art more than science, and here we will discuss few Java best practices related to Exception handling. Th ese Java best practices are f ollowed even in standard JDK libraries, and several open source code to better deal with Errors and Exceptions. This also comes as handy guide of writing robust code for Java programmers. Read more �

How to Fix java.net.ConnectException: Connection refused: connect in Java

java.net.ConnectException: Connection refused: connect is one of the most common networking exceptions in Java. This error comes when you are working with client-server architecture and trying to make TCP connection from the client to the server. Though this is not as cryptic as java.lang.OutOfMemoryError: Java heap Space or java.lang.UnsupportedClassVersionError , it�s still a frequent problem in distributed Java applications. java.net.ConnectException: Connection refused: connect also comes in the case of RMI (Remote Method Invocation) because RMI also uses TCP-IP protocol underneath. While writing client socket code in Java, You should always provide proper handling of this exception . Read more �

How to Fix Must Override a Superclass Method Error Eclipse IDE Java | @Override annotation With interface methods

One of annoying error while overriding Java method in Eclipse IDE is must override a superclass method error , This error is quite frequent when importing Java projects and still I haven't seen any permanent solution of it. Must override a super class method error comes in Eclipse, if you h ave Java Class that implements interface and overrides method from interface and uses @Override annotation . Unfortunately Eclipse defaults to Java 1.5, which only recognize @Override annotation for overriding method from super class and not from interface. This creates lots of confusion between Java programmers as not every one is aware of this subtle difference of using @Override annotation with class and interface methods and they start looking classpath and path suspiciously. @Override annotation for interface methods are only available from Java 1.6 and if you use @Override while overriding interface method tha n you will get must override a superclass method error. In this Java ...

Spring - java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener Quick Solution

If you have worked in Spring MVC than you may be familiar with java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener , which is common problem during deployment. Spring MVC throws java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener , when its not able to find org.springframework.web.context.ContextLoaderListener class which is used to load spring MVC configuration files like application-context.xml and other Spring Framework configuration files defined in context-param element of web.xml in an Spring MVC web application as: Read more �

How to fix java.lang.classcastexception cannot be cast to in Java - cause and solution

As name suggests ClassCastException in Java comes when we try to type cast an object and object is not of the type we are trying to cast into. In fact ClassCastException in Java is one of most common exception in Java along with java.lang.OutOfMemoryError and ClassNotFoundException in Java before Generics was introduced in Java 5 to avoid frequent instances of java.lang.classcastexception cannot be cast to while working with Collection classes like ArrayList and HashMap , which were not type-safe before Java 5. Though we can minimize and avoid java.lang.ClassCastException in Java by using Generics and writing type-safe parameterized classes and method , its good to know real cause of ClassCastException and How to solve it. In this Java tutorial we will see Why java.lang.ClassCastException comes and how to resolve ClassCastException in Java. We will also see how to minimize or avoid ClassCastException in Java by using Generics , as prevention is always better than cure. Read mor...

Tutorial How to fix java.io.NotSerializableException: org.apache.log4j.Logger Error in Java

Image
java.io.NotSerializableException: org.apache.log4j.Logger error says that instance of org.apache.lo4j.Logger is not Serializable. This error comes when we use log4j for logging in Java and create Logger in a Serializable class e.g. any domain class or POJO which we want to store in HttpSession or want to serialize it. As we know from 10 Java Serialization interview question that, if you have a non serializable class as member in a Serializable class, it will throw java.io.NotSerializableException Exception. Look at the below code : public class Customer implements Serializable{ private Logger logger =   Logger.getLogger(Customer.class) ...... } If instance of Customer will be stored in HttpSession or Serialized externally it will throw " java.io.NotSerializableException: org.apache.log4j.Logger" because here logger instance is neither static or transient and it doesn't implement Serializable or Externalzable interface. H...

Invalid initial and maximum heap size in JVM - How to fix

I was getting "Invalid initial heap size: -Xms=1024M" while starting JVM and even after changing maximum heap size from 1024 to 512M it keep crashing by telling " Invalid initial heap size: -Xms=512m , Could not create the Java virtual machine". I check almost everything starting from checking how much physical memory my machine has to any typo in JVM parameters , only to find out that instead of M, I had put MB there. Java accepts both small case and the capital case for Kilo, Mega, and Gigs. you can use m or M, g or G etc but never used MB, GB or KB. Similar problem can occur with maximum heap size specified by -Xmx . Also from Java 6 update 18, there is change on default heap size in JVM. Read more �

Java Error : 'javac' is not recognized as an internal or external command

So you are trying to compile your Java source file and getting " 'javac' is not recognized as an internal or external command" . If this is your first Java program or HelloWorld than I suggest to go through How to compile and run HelloWorld in Java because that explains what do you need before you compile and run any Java program. If you have crossed that level and knows about How to set PATH in Java then there is something wrong while setting PATH in Java. Anyway let's see when do you get this error and from where does 'javac' is not recognized as an internal or external command comes. This is a standard error in Windows command line when you type a command which is not available in System PATH, here javac command which is used to compile Java source file and produces class files are not in PATH. Best way to verify this is executing the following command : # echo %PATH% If you see your JDK installation folder or JAVA_HOME in PATH and included bin d...