Posts

Showing posts with the label debugging

How to fix Failed to load Main-Class manifest attribute from jar - Java Eclipse Netbeans Tutorial

If you have tried creating JAR file and running Java program form command line you may have encountered " Failed to load Main-Class manifest attribute from jar" , This error which haunts many Java programmer when they enter into command line arena and tries to create JAR file in command line or IDE like Netbeans and Eclipse . Major problem with "Failed to load Main-Class manifest attribute from jar" error is that, it�s unnecessary creates panic which it doesn't deserve, may be because process involves of creating and running JAR is not that common like running Java program using "java" command. Anyway in this Java tutorial we will see Why " Failed to load Main-Class manifest attribute from jar" comes and How to fix Failed to load Main-Class manifest attribute from jar error. Read more �

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...

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver - cause and solution

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver Exception comes when you try to connect Oracle database from Java program and Oracle driver is not available in Classpath . We have already seen How to connect Oracle database from Java program and found that, In order to connect to Oracle database, we load and register driver using Class.forName("oracle.jdbc.driver.OracleDriver") and this cod e loads a class at runtime using Reflection which throws ClassNotFoundException if the class in question e.g. " oracle.jdbc.driver.OracleDriver " is not found. I have already listed down variou s reason of ClassNotFoundExcepiton in Java , which is also applicable in this case. By the way java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver is similar to java.lang.ClassNotFoundException: MySQL.jdbc.driver.MySQLDriver w hich comes if you try to connect MySQL database from Java program and corresponding driver is not in your classpath. You ca...