For whatever reason I had to change pc's as a result of the change I now have to use Java 6 (the final update) Instead of java 7. When importing my existing project to Java 6 I get the following error in my auto generated code that was generated by Netbeans and is not modifiable
cannot find symbol
symbol: variable Type
location: class Window
frame.setType(java.awt.Window.Type.POPUP); //Type is underlined
The output for the error is as follows:
javac: invalid target release: 1.7
Usage: javac <options> <source files>
use -help for a list of possible options
C:\Users\Adminstrator\Downloads\NetBeansProjects\NetBeansProjects\Pat0.3\nbproject\build-impl.xml:915: The following error occurred while executing this line:
C:\Users\Adminstrator\Downloads\NetBeansProjects\NetBeansProjects\Pat0.3\nbproject\build-impl.xml:268: Compile failed; see the compiler error output for details.
What does this do? Is it necessary, would deleting that the component help? Which component is it, is there a quick fix?
Your build.xml specifies the target="1.7" flag to javac, which java 6 doesn't know how to interpret. Changing it to 1.6 will technically get past that error.
However, the enum Window.Type was added in Java 7, so you simply can't expect changing the target to work; your project's source uses Java 7 features. I'm sure that's not the only one.
Your options are therefore to methodically go through and remove/replace all Java 7 code (likely introducing some bugs) or just to.. install Java 7.
There is somewhere in your project a setting for the java compiler that tells it to generate classes for jre7. javac from jdk6 cannot generate classes for that version, hence the error. So you should look into the properties of your project and set up javac to generate classes for jr6. You might also have fix some of your non-generated code if for example you have used features that came with java 7 such as diamond operator or multy catch block etc.
Also the javadoc for Window.Type states it is available only since 1.7. You might want to re-generate that code or better yet just install jdk7.
Related
I am trying to use Jasmin to convert Jasmin assembly code to a Java class file. Using the Hello World example from here.
The following error is returned:
Exception in thread "main" java.lang.NoSuchMethodError: jasmin.parser.parse()V
at jasmin.ClassFile.readJasmin(ClassFile.java:1160)
at jasmin.Main.assemble(Main.java:81)
at jasmin.Main.run(Main.java:200)
at jasmin.Main.main(Main.java:157)
I suspect that it may be a problem with the Java version since Jasmin seems to be old and probably implemented using an older Java version.
So far I have tried to run the example using this command: java -jar jasmin.jar test.j.
I have tried to run it with Java 8, 7, 6 and 4 unsuccessfully.
The version of Jasmin I have used is 2.4.
Furthermore I have also tried to download Jasmin's source code and compile it manually, with the same result.
Does anybody have any pointers or ideas on how to solve this issue?
The issue is that, if you have other versions of cup in Java's classpath, jasmin might run intro troubles and it will throw a NoSuchMethodError.
To fix this, just remove the other CUP versions from Java's classpath.
All credit goes to #MargaretBloom for finding the issue.
I am having a doubt.
My understanding is that jdk has [ jre + development tools (Java, javac, debugger etc.) + source code (src.zip) ].
Now working of java compiler is nothing to do with the running of class file.
If I am compiling a .java file then from where the java compiler is importing the package?
I could find the packages under jre.
If I do not opt to install jre while installing jdk, does that mean I will not be able to compile the java file having import statement?
Please help.
First, as a minor remark, a statement like
import java.util.List;
just introduces an abbreviation, allowing you to use the simple word List later in your code instead of the full class name java.util.List. So it's not so much the import statement itself, but the usage of a class like java.util.List that needs some explanation.
You understand correctly that, to compile your java file, the compiler needs some information about every class you use, and it typically finds this information in some jar file containing that class.
Now, where is this jar file containing the java.util.List class that the compiler reads? You're correct, it comes from the JRE, from the rt.jar that's part of the system classpath (the Java compiler itself is a java program that needs the basic classes itself, so wherever you successfully run javac, you always have an rt.jar available).
If your source code used a class from some other library, you'd have to specify that library on the javac command line, using an option like -cp.
Jdk = JRE + other tools like you mentioned.
When you are compiling your java file and you are using java inbuild library then it uses rt.jar to resolve dependency i.e import statements.
You can refer below link for the difference
What is the difference between JVM, JDK, JRE & OpenJDK?
I'm trying to compile my Java program, however I am getting a "Deprecated File" error.
I normally compile the file by typing "Javac FileName.java", however I get an error saying:
FileName.java uses or overrides a depreacted API.
Recompile with Xlint-deprecation for details.
What do I type into the command line to make it run?
It's not an error, just a warning.
The compiler will still produce a class file and you will be able to run it. However, it's a good idea to address the warning, since using deprecated API could lead to more problems later on.
If you choose to see the warnings, you can do this:
javac -Xlint:deprecation FileName.java
If you don't have a deprecation
javac -Xlint Filename.java
I was getting the same exception in running a gradlew build. I discovered that the path included Java 1.7 and my JAVA_HOME variable path had 1.8 specifed. Once I updated the path to 1.8, the build was successful.
Had the similar issue and setting the PATH to the correct file that contains the JDK worked.
For windows,
search environnement variables > select edit environnement variables > Enter JAVA_HOME as variable and set the value to the jdk file.
I am trying to convert a proprietary, third party IDL into java. I downloaded the IDL, opened up cmd.exe, navigated to the directory containing the IDL files, and then typed in the following command which was given explicitly by the provider of the third party IDL:
java com.sun.tools.corba.se.idl.toJavaPortable.Compile -fallTIE -pkgPrefix types org.hl7 -pkgPrefix CTSMAPI org.hl7 -pkgPrefix CTSVAPI org.hl7 CTSVAPI.idl
Unfortunately, this is throwing the following error in the command line:
Error: could not find or load main class com.sun.tools.corba.se.idl.toJavaPortable.Compile
I googled and found the definition of the class at this link.
I typed in java in the command prompt and got a list of methods, indicating that I can call java from the command prompt in that directory. Other web sites indicate that com.sun.tools.corba.se.idl.toJavaPortable.Compile has been a part of the jdk since at least version 1.3. So why am I getting this error?
The provider doesn't know what he's talking about. You should use the 'idlj' tool, with the same or corresponding arguments, not this undocumented invocation.
You may be getting the error because you're running the JRE 'java', not the JDK one. But it's wrong wrong wrong. Use idlj.
as we "No keyword should be used as an Identifier in java". But there will be some words like asser or enum or any other which have been added as keyword in version 1.4, 1.5 resp. So if any older version code is used to compile with new javac, what happens if that code contains these words as an identifier?
When older code uses an identifier that is a keyword in the current version you are trying to compile the code with, you will simply get an error. The compiler won't be able to tell from the code what version it was written for.
You'll get a compile error. But you can use already compiled classes if you aren't going to make changes in your legacy code.
Thanks for your answer, After searching i got to know the answer as, if any keyword is used as an identifier then we have to compile it with its compliant compiler otherwise it gives a compiler error. So to do that say suppose if my code has a assert as an identifier which works fine with java 1.3. So i can compile it as
javac -source 1.3 example.java
which compiles fine.