JDeveloper: AnnotatedNoClassDefFoundError - java

I have created a new Java Application in JDeveloper. That application only uses the Java application. No Swing and no ADF technologies are used.
I have created a new class with a static main method.
When I'm trying to compile the project, this error is shown:
Error: Exception thrown during compilation: oracle/classloader/util/AnnotatedNoClassDefFoundError
I'm trying to find on Google any reference of this, but each page that I see talks about ADF.
Anybody knows how to fix that issue?
Edit: the class code:
package wewe;
public class Class1 {
public Class1() {
}
public static void main(String[] args) {
Class1 class1 = new Class1();
}
}

It seems that I didn't installed correctly the JDK, and JDeveloper didn't reported. Now all works.

Related

Eclipse - class file is generated automatically even though java file has compilation error

I have created a simple java file having compilation error(Removed ; in 4th line).
public class Test {
public static void main(String args[])
{
System.out.println("Hi")
}
}
After saving If I see bin folder I can see class file(Test.class) being created.Whereas if we compile the same java code through windows command prompt class file is not created.
Eclipse generated compiled class file (below)
public class Test
{
public static void main(String[] paramArrayOfString)
{
throw new Error("Unresolved compilation problem: \n\tSyntax error,
insert \";\" to complete BlockStatements\n");
}
}
Can you please let know why we see 2 different behavior for the file having compilation error in it.
Eclipse's focus is allowing you to do software development. The behavior you've seen allows you to e.g. start unit tests on parts of the class that doesn't have compile errors to check if existing behavior is still the same at that part of the class while you refactor other parts or add new functionality.

Java - can't run program in Eclipse

I can't run HelloWorld in Eclipse - it shows message:
Error: Main method not found in class com.taksila.javabyexample.overview.HelloWorld, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Here is my code:
package com.taksila.javabyexample.overview;
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hi Planet");
}
}
Code is correct. Try to restart IDE or just save sketch :-)
Yes, your code is definitely correct. Save it, restart the IDE, and wait to load all of its components. Then again run it!

main method with class name and file name

My file name is Temp.java and inside it I have this. I'm using eclipse IDE
/*package*/ class Test {
public static void main(String args[]) {
System.out.println("test");
}
}
So I was unable to run this as java application. I change my class name to Temp
class Temp {
....
}
Now I can. Can someone explain me why ?
This is probably a limitation of Eclipse. The code runs well from command line.
As I understand, you are trying to embed your unit tests in the same file with the class under test. This is a nice idea and I totally concur with it. You can read more about how you can succeed in Ben J. Christensen's blog post. Generally, he suggests placing the tests in a static inner class, not a standalone class in the same file.
An example from the Netflix Hystrix framework: HystrixCircuitBreaker.UnitTest
The code below, located in Temp.java, compiles and runs fine with Netbeans:
class Whatever {
public static void main(String[] args) {
System.out.println("hello");
}
}
The problem is with eclipse, i think you are trying to run using right click -> run as -> Java Application, unfortunately eclipse is not showing this option if the class is not public.
But you can still run the class using Alt+Shift+X,J.
Its not the problem with Java, its with Eclipse.
The name of the file should be the same as the class name which is public and has the main() method. In your first case the file name Temp.java will compile and will create Test.class file not Temp.class because there is no Temp class declared in your file.
after .class file is created , run it with java Test
so here's an example
//Filename abc.java
public class hi
{
public static void main(String[] args)
{
System.out.println("Hell");
}
}
the output
abc.java:1: class hi is public, should be declared in a file named hi.java
public class hi
^
1 error
but if you do this
//Filename abc.java
class hi
{
public static void main(String[] args)
{
System.out.println("Hell");
}
}
it will create hi.class file so
D:\>java hi
Hell
The class (which main should be run) inside the .java file must have the same name as the file. If the class is not public (as in your case) the class will compile but it can't be run since Eclipse tries to load the class according to the file name.

Why IntelliJ displays error in simple java programm?

I run IntelliJ. Simple project and received println in red.
package test;
public class Main {
public static void main(String[] args) {
System.out.println("Console is.");
}
}
Error:
Cannot resolve method 'println'...
I have checked that in module setting JDK is. What another I should check? Thanks.
I needed to re-start IntelliJ after installing it.

Dynamic Link Library & Java

I made a dll in C++ and wrote this class in java:
public class VolumeControl {
public native float GetVolume();
public native void SetVolume(float val);
public native void VolumeUp();
public native void VolumeDown();
public native void Mute();
static {
System.load("some_path/VolumeControl.dll");
}
}
it works good, if I call functions from this file, but when I'm trying to do this:
public class Server {
public static void main(String[] args) {
VolumeControl ctrl = new VolumeControl();
ctrl.Mute();
}
}
I get this:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
RemoteControl.VolumeControl.Mute()V
Both classes are in the same package, of course. How can I solve it? Thanks.
Update1: OK the problem was, that I added these classes to package. When I move them to default package, everything works good. But now if I want to use this dll with different packages, I need to rebuild it.
Update2: Actually I can't add it to package at all, when I'm trying: #javah VolumeControl, I get Error:
Could not find class file for 'VolumeControl'.
Update3: I added manually name of package to C++ functions and it works. Thanks.
The use of javah utility may help if integrated into a makefile to ensure the interface is always assumed on both side (client/server).

Categories

Resources