Showing posts with label JRE Error. Show all posts
Showing posts with label JRE Error. Show all posts

Tuesday, October 4, 2011

Override Annotation JDK 5 v/s JDK 6

Sometime problems are way beyond your understanding and you could not find the solution for them.

Problem 1

I faced one such problem while I was working on eclipse and JDK5. I created a derived class extending the abstract class. Following is the definition of my abstract class.


public abstract class test {
public abstract void unimplementedMethod(Object[] params);
}

I overrode my abstract class in the class mentioned below.

public class ImplementedTest extends Test{
@Override
public void unimplementedMethod(Object[] params) {
// TODO Auto-generated method stub
}
}

Eclipse was showing a red around the method I had implemented and it was displaying error mentioned below. 
The method unimplementedMethod(Object[]) of type ImplementedTest must override a superclass method

As I see I have not done anything incorrect, I took the exact signature required and pasted in the derived class. After couples of hours of brain storming I found out a import definition of Object. 

import org.omg.CORBA.Object;
public class ImplementedTest extends Test{
@Override
public void unimplementedMethod(Object[] params) {
// TODO Auto-generated method stub
}
}

So how did It manage to sneak into my class? Sometimes eclipse assist you to add required import statements. This time also it appended the import statements, but it appended one additional statement which was not required, and to figure out such a small thing( From the code of 2k lines) it took hours of efforts.

Problem 2
In JDK5, @Override annotation was not working for me. I had an interface and one of my class was implementing the interface.

public interface Test {
public void unimplementedMethod(Object[] params);
}

Class implementing the interface is as follows:

public class ImplementedTest extends Test{
@Override
public void unimplementedMethod(Object[] params) {
// TODO Auto-generated method stub
}
}

Eclipse shows the error mentioned below:
The method unimplementedMethod(Object[]) of type ImplementedTest must override a superclass method

If I remove @override from here it works fine.
If I change my JDK to JDK6, it works without showing any error.
If I change Test interface to test abstract class, it works.

public abstract class Test {
 public abstract void unimplementedMethod(Object[] params);
}

Class implementing the interface is as follows:

public class ImplementedTest extends Test{
@Override
public void unimplementedMethod(Object[] params) {
// TODO Auto-generated method stub
}
}

It works fine. This was non-understandable behavior along with sun has not provided any information about such behavior.

But this behavior has been encounter by different individuals and according to them, in JDK5 when you are implementing the interface then JDK5 do not understand it is override and @Override annotation does not work whereas when you are overriding the method from other class then @Override annotation work without any problem. This confusion was removed later in JDK6. In JDK @override works for interface and general classes.

Source of Reference:

Thursday, September 22, 2011

Eclipse/ANT Error Specified VM install not found



My company provided me new laptop and happily I moved from my old rusted desktop to new shining, powerful and portable laptop. Everything was copied without problem and I started working. But is not it strange to see everything working perfectly fine? I was stunned but happy as well. 

I started using the installed application. Eclipse was working fine until I tried building (Using ant) my application. Ant showed me a scary popup displaying "Specified VM Not found..." 



Simple solution, there is JDK/JRE problem with the system. Correct the JRE and JDK of the project. I did, but it did not work. I googled and found following 2 solutions.

You might even face this problem when you upgrade ant plug-in.

Solution 1
Remove the file which stores build information about the project and restart the eclipse. You can find the respective file in "${PROJECT_WORKSPACE}/.metadata/.plugins/org.eclipse.debug.core/.launches/${PROJECT_NAME} build.xml.launch"

Solution 2 (Location and Screen Shot may differ for different Eclipse Version. Following screen shot and paths are valid for Eclipse Version 3.7)

Go to RUN->External Tools ->External Tools Configurations… 


It will open console below. Select your build.xml(in my case it is abc build.xml). Move to JRE tab. 



Select the appropriate JRE.



Apply the changes and run the build xml. No need to restart eclipse, and you will not face the problem again.

Bmmm, Solved. Saved time.