Showing posts with label error and exception. Show all posts
Showing posts with label error and exception. Show all posts

Thursday 29 August 2013

Top Most Eclipse No Java Virtual Machine was found Windows JRE JDK 64 32 bit Error

One of my reader was installing Eclipse in his Windows 7 x86 machine and emailed me about this error "A java Runtime Environment (JRE) or Java Development kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found". Before getting into details and trying to find root cause and solution of Eclipse Java Virtual Machine not found error, let's see some background about Eclipse. Eclipse is a popular Java IDE, which assist on coding, debugging and running Java program, but key point is, Eclipse itself need Java to launch and run. By default Eclipse scan your PATH and look for any JRE, if it founds suitable JRE than it runs otherwise it throws "A java Runtime Environment (JRE) or Java Development kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found". Now, In order to install JRE, you can either download JDK or a JRE from Oracle's Java download site. For Java programmers, I suggest to install JDK because it comes with bundled JRE.  Once you install JDK, its good to set your JAVA_HOME environment variable, and subsequently include JAVA_HOME/bin into your PATH. JAVA_HOME contains "java" command line utility which is what required by Eclipse to run. Alternatively you can install JRE on your windows 7 machine, and include its bin directory into PATH that contains javaw command, which can also run Eclipse or any Java program. By the way there is subtle difference between java and javaw, which is worth knowing. You can get "No Java virtual machine was found" error during fresh install or reinstalling Eclipse, but root cause always lies in PATH which is quite obvious with error itself.
Read more »

Wednesday 28 August 2013

Top Most 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.OutOfMemoryErrorand 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 ArrayListand 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 more »

Monday 26 August 2013

Top Most 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.xmlin an Spring MVC web application as:
Read more »

Sunday 25 August 2013

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

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 staticor transientand it doesn't implement Serializable or Externalzable interface.

How to solve java.io.NotSerializableException: org.apache.log4j.Logger

How to fix java.io.NotSerializableException: org.apache.log4j.Logger Error in JavaSolving java.io.NotSerializableException: org.apache.log4j.Logger  is simple, you have to prevent logger instance from default serializabtion process, either make it transient or static. Making it static final is preferred option due to many reason because if you make it transient than after deserialization logger instance will be null and any logger.debug() call will result in NullPointerException in Java because neither constructornot instance initializer block is called during deserialization. By making it static and final you ensure that its thread-safeand all instance of Customer class can share same logger instance, By the way this error is also one of the reason Why Logger should be declared static and finalin Java program. Just make following code change to fix java.io.NotSerializableException: org.apache.log4j.Logger in Java.

public class Customer implements Serializable{

private static final Logger logger =  Logger.getLogger(Customer.class)

......

}

That's all on how to fix java.io.NotSerializableException: org.apache.log4j.Logger in Java. We have seen what cause java.io.NotSerializableException: org.apache.log4j.Logger, it's because Logger class is not Serializable but we also learned that there is no point serializing Logger instance and better to make Logger static and final.

Other Serialization and troubleshooting articles from Javarevisited Blog

Top Most 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 and finally keywordJava  programming language also allows you to create new exceptions and throw them using  throw and throws keyword. 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. These Java best practices are followed 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 »

Wednesday 21 August 2013

Top Most 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 for almost everything starting form 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 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 »

Monday 19 August 2013

Top Most 3 ways to resolve NoClassDefFoundError in Java

What is Exception in thread "main" java.lang.NoClassDefFoundError?
I know how frustrating is to see Exception in thread "main" java.lang.NoClassDefFoundError  Which is a manifestation of NoClassDefFoundError in Java , I have seen it couple of times and spent quite a lot time initially to figure out what is wrong , which class is missing etc. First mistake I did was mingling java.lang.ClassNotfoundException and NoClassDefFoundError, in reality they are totally different and second mistake  was using trial and error method to solve this java.lang.NoClassDefFoundError instead of understanding why NoClassDefFoundError is coming, what is real reason behind NoClassDefFoundError and how to resolve this. In this Java tutorial I have tried to rectify that mistakes and uncover some secrets of NoClassDefFoundError in Java and will share my experience around it. NoClassDefFoundError is not something which cannot be resolved or hard to resolve it’s just its manifestation which puzzles most of Java developer. This is the most common error in Java development along with java.lang.OutOfMemoroyError: Java heap space and java.lang.OutOfMemoryError: PermGen space  Anyway let’s see Why NoClassDefFoundError comes in Java and what to do to resolve NoClassDefFoundError in Java.
Read more »

Thursday 15 August 2013

Top Most 'javac' is not recognized as an internal or external command - cause and solution

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 does you get this error and from where does 'javac' is not recognized as an internal or external command comes. This is an 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 following command :

# echo %PATH%

If you see your JDK installation folder or JAVA_HOMEin PATH and included bin directory which contains all java binaries including javac and java commands which is used to compile and run Java program. Most likely your PATH may not have JDK/bin in PATH, if that's the case just include bin folder of JDK in your PATH. See how to set PATH for Java in Windows for step by step guide.
Read more »

Thursday 8 August 2013

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

java.net.ConnectException: Connection refused: connect is one of the most common networking exception in Java. This error comes when you are working with client-server architecture and trying to make TCP connection from client to 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 case of RMI (Remote Method Invocation), because RMI also use TCP IP protocol underneath. While writing client socket code in Java, You should always provide proper handling of this exception. In this Java tutorial, we will see why connection refused exception comes and how to solve java.net.ConnectException: Connection refused: connect Exception in Java.
Read more »

Top Most How to get current stack trace in Java for a Thread - Debugging Tutorial

Stack trace is very useful while debugging or troubleshooting any issue in Java. Thankfully Java provides couple of ways to get current stack trace of a Thread in Java, which can be really handy in debugging. When I was new to Java programming, and didn’t know how to remote debug a Java application, I used to put debug code as patch release, which uses classpath to pick debug code for printing stack trace and shows how a particular method is get called and that some time provide vital clue on missing or incorrect argument. Now, When I have couple of Java debugging tips at my sleeve, I still think knowledge of  how to get current stack trace in Java for any Thread, or simply print stack trace from any point in code worth knowing. For those who are not very familiar with stack trace and wondering what is stack trace in Java, here is quick revision. Thread executes code in Java, they call methods, and when they call, they keep them in there stack memory. You can print that stack trace to find out, from where a particular method is get called in execution flow. This is especially useful if you are using lot of open source libraries, and don’t have control on all the code. One of the most familiar face of stack trace in Java is printing stack trace using Exception.printStackTrace(), when an Exception or Error is thrown in Java. In this Java tutorial, we will look at couple of ways to print and get current stack trace of a Thread in Java.
Read more »

Saturday 3 August 2013

Top Most How to Fix Must Override a Superclass Method Error Eclipse IDE Java

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 have 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 methodthan you will get must override a superclass method error. In this Java and Eclipse tutorial we will see how to fix must override a superclass method error in eclipse but before that we will reproduce this error in a manner which will clear that Eclipse will complain only for methods which is overridden from interface.
Read more »

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Labels

Core Java programming core java interview question Core Java Faq's Servlets coding database jsp-servlet spring Java linux unix interview questions java investment bank Web Services Interview investment bank mysql Senior java developer interviews best practices java collection tutorial RMI SQL Eclipse FIX protocol tutorial tibco J2EE groovy java questions SCJP grails java 5 tutorial jdbc beginner error and exception Design Patterns Java Programming Tutorials fundamentals general object oriented programming xml Java Programs Hibernate Examples Flex JAMon Java xml tutorial logging Jsp Struts 2.0 Sybase and SQL Server debugging java interviews performance FIX Protocol interview questions JUnit testing WebSphere date and time tutorial experienced java IO tutorial java concurrency thread Ejb Freshers Papers IT Management Java Exapmle Java Script SQL and database tutorial examples Scwcd ant tutorials concurrency example and tutorial future state homework java changes java threading tricky Agile Business of IT Development JSTL Java JSON tutorial Java multithreading Tutorials PM Scrum data structure and algorithm java puzzles java tips testing tips windows 8 5 way to create Singleton Object Architect Interview Questions and Answers Architecture Architecure Bluetooth server as swing application that searches bluetooth device in 10 meter circle and show all devices. You can send file to any bluetooth device. C Programming CIO Callable Statement in Java Circular dependency of Objects in Java Comparable Example in Collection Custom annotation in Java Developer Interview Divide and rule example in java Drupal Example of Singleton Pattern FIX protocol ForkJoin Example in Java 7 Get data from dynamic table with Java Script Git HTML and JavaScript Health Hello World TCP Client Server Networking Program Hibernate Basics Hibernate Interview Question Answer J2EE Interview Question And Answers J2ME GUI Program JEE Interview QA JMS interview question Java J2EE Hibernate Spring Struts Interview Question Java System Property Java Threads Manager Portlets Provident Fund Read data from any file in same location and give the required result. Reading Properties File in Java Redpoint Rest WebService Client Rest Webservice Test SAL join with ven diagram SCP UNIX COMMAND SSL Singleton Pattern in Java Spring Bean Initialization methods and their order Spring Interview Questions Struts Struts 2.0 Basics Struts 2.0 Design Pattern Submit Html Form With Java Script On The Fly Unix executable For Java Program XOM DOM SAX XP books computers core java; core java; object oriented programming data structure; java investment bank; design pattern dtd duplicate rows in table get browser name with jquery grails podcast inner class java beginners tutorial java cache java networking tutorial java spring java util; java collections; java questions java.java1.5 linked list mailto function with all browser oracle database oracle duplicate rows orm schema social spring mvc questions struts transaction tricks tweet windows xslt