When opening any Java project, or maven project, new or old, Java throws "Error: Could not find or load main class App" at runtime. Java will only run if "package foo;" is commented out i.e. "//package foo;".
I am using the code runner extension, which works with every other language. It runs as expected in java if the package statement is excluded or commented out.
This is able to be replicated in every new java program created or opened inside VS Code, even projects created in IntelliJ (Which run as expected) and opened in VS Code.
Environment:
Operating System: Mac OSX Mojave 10.14.4
JDK version: 1.8.0_202
Visual Studio Code version: 1.33.0
Java extension version: 0.6.0
I could never get my java code to run inside VS Code, until I removed the package statement (commented it out). Once the package statement is removed my code runs as expected, but has a 'problem' inside VS Code saying "The declared package "" does not match the expected package "app"Java(536871240)"
//package app;
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello Java");
}
}
Example1
Example2
Make sure you've already setup the JDK environment in the right way
Try to clean your workspace:Clean the workspace directory
Make sure to reload a new workspace after you finished all the above steps.
I fixed by using the above steps when I have this error. Hope it can also works on your side.
I'm using Lombok to add logging to my Java applications. I've been using this for some time, but since I upgraded my IDE from IntelliJ 13 Community edition to 14 Ultimate, I get the following compile errors (using maven):
error: log has private access in SesameServer
This error originates in a subclass of SesameServer:
#Slf4j
public class AnnotatorServices extends SesameServer {
#Override
protected void initialiseRDFStoreManager(Series<Parameter> parameters) throws RepositoryConfigException, RepositoryException {
log.info("<< ------ Annotator Services ------- >>");
}
}
Of course SesameServer also uses the #Slf4j annotation to add logging. The #Slf4j annotation adds the line:
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SesameServer.class);
to the class in which it is used (both SesameServer and AnnotatorServices where SesameServer.class is of course replaced by AnnotatorServices.class).
Apparently the compiler thinks I want to use the log variable from SesameServer instead of AnnotatorServices (both classes have variables with the same name).
How can I prevent this problem, i.e. that the SesameServer.log is used instead of AnnotatorServices.log?
NOTE: This still comes up for anyone else googling this error message; so adding my fix hope this helps.
I had a similar issue after reopening a project from pom.xml.
Since my parent class SesameServer was already built in a different module and used a dependency; when I compiled my AnnotatorServices I also saw the error: log has private access in SesameServer
To fix it I just had to turn on Annotation Processing for the module containing AnnotatorServices.
In IntelliJ Community 2017.1.6 the check box was found under:
File -> Settings
"Build, Execution Deployment -> Compiler -> Annotation Processors"
Tick the "Enable annotation processing"
Following steps worked for me
Install Lombok Plugin in Settings=>plugins under Marketplace search for Lombok and install.
Then in IntelliJ Community 2017.1.6 go to File->Invalidate Caches/ Restart and click on both.
Did the trick for me. All the best.
Make sure your subclass is also annotated properly with #Slf4j.
Update your lombok plugin. Sometimes idea does not display the new updates so goto settings => plugins and search for "lombok"
Click "update" and restart idea
I have a Java project which depends on a Scala project. Inside that Scala project, there is a particular method that uses two #throws(classOf[<some exception>]):
#throws(classOf[ExtensionException])
#throws(classOf[LogoException])
def perform(args: Array[Argument], context: Context)
However, intellij doesn't seem to know about both when I override the method:
The error is that the base method does not throw ExtensionException. The code compiles fine. Note that LogoException appears to be okay when I delete ExtensionException from throws declaration.
So, is there a way I can get Intellij to respect both throws declarations? Or is this a bug?
I'm pretty sure this is a bug in IntelliJ. I've run into it myself, and reported it at http://youtrack.jetbrains.com/issue/SCL-7454
I'm experimenting with Aspect-Oriented Programming. I've installed the AspectJ-Plugin in Eclipse and followed all the steps mentioned in this tutorial.
All connections between the created aspects work, but when I try to run the project, I receive the following exception:
HelloException in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 6 in method helloworld.World.<clinit>()V at offset 0
at helloworld.Hello.sayHello(Hello.java:11)
at helloworld.Hello.main(Hello.java:6)
When I empty the class World.aj and run the project, everything works and I receive the expected "Hello" in the console.
Here are the classes I created during the tutorial:
Hello.java
package helloworld;
public class Hello {
public static void main(String[] args) {
sayHello();
}
public static void sayHello() {
System.out.print("Hello");
}
}
World.aj
package helloworld;
public aspect World {
pointcut greeting() : execution(* Hello.sayHello(..));
after() returning() : greeting() {
System.out.println(" World!");
}
}
the problem doesn't seem related to AOP.
I think this is the same eclipse bug described here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=362591
Ayushman Jain 2011-11-02 02:47:32 said:
If you're stuck, please use the VM argument -XX:-UseSplitVerifier to run the
program. I confirm that there is no verify error with this option.
May you can also try to download the latest version of eclipse.
I don't have the points to comment on #KC answer, which worked for me,
so leaving this as an additional answer
-XX:-UseSplitVerifier
did work for me
I have an AspectJ project that was running fine in eclipse 3.7
then all of a sudden started getting that error
adding the -XX:-UseSplitVerifier to the launcher configuration solved it.
I also followed the tutorial, and encountered the same error. And here is how I solved it.
I found out that that the execution environment JRE selected by default with my eclipse, JavaSE-1.7, had an issue with AspectJ. So what you have to do, is change the execution environment JRE, choose for example JavaSE-1.6.
After, you can follow the tutorial, and obtain the desired output! :)
Hope this helps!
I am executing a junit test case
I got the following error,
A fatal error has been detected by the Java Runtime Environment:
Internal Error (classFileParser.cpp:3174), pid=2680, tid=2688
Error: ShouldNotReachHere()
JRE version: 6.0_18-b07
Java VM: Java HotSpot(TM) Client VM (16.0-b13 mixed mode windows-x86 )
Can any body please suggest the solution to resolve
I got the same problem, but with alot of googling I found the answer! See this page
Quote from the link:
# An unexpected error has been detected by Java Runtime Environment:
#
# Internal Error (classFileParser.cpp:2924), pid=5364, tid=6644
# Error: ShouldNotReachHere
That's because we are using Android's JUnit stub implementation. Go to Run -> Run As -> Run configurations again and in the recently created JUnit configuration Classpath's Bootstrap Entries remove Android Library
Then Add Library, using Advanced... button, and add JRE System Library and JUnit 3
Apply and Run
Try this, it worked for me.
You'll need to take this up with Sun -- looks like a JVM bug to me. If it's reproducible, you should be able to run java in such a way as to generate more details (e.g. -verbose, etc). If you can reduce it to a minimal case that triggers the bug (source code always helps!), that also goes a very long way.
http://java.sun.com/developer/technicalArticles/bugreport_howto/index.html
http://bugreport.sun.com/bugreport/crash.jsp
In the meantime, you might want to try it with a different JVM implementation (maybe even an older patch level of the Sun JRE).
Go to Run As -> Run Configurations... and select the configuration you are using.
Select the Class Path tab and select BootStrap Entries.
Click on Advance, then Add Library and select JRE System Library.
Bring it up and make it the first entry in the BootstrapEntries List.
Apply and Run...
Another possible explanation: hardware failure. Ruled out if you can reproduce the error on different machines.
I resolved this by
Quit eclipse
Delete the bin and gen directories in your project
Start eclipse
Rebuild your project
I just recently found solution for this issue that was posted by devdanke:
"As of 11-July-2010 and Android 2.1, the work around I use is to segregate tests into different classes. Any test(s) that don't call any Android APIs go into their own classes. For each of these classes, I remove the reference to Android in their Run Configurations, Classpath tab."
The problem with having it configured class by class is then is not possible to run all tests in project. Better approach is creating 2 test projects with different sets of libraries.
Standard Android JUnit Test project can be created following link, and sample test class looks like:
import android.test.AndroidTestCase;
public class ConverterTest extends AndroidTestCase {
public void testConvert() {
assertEquals("one", "one");
}
}
Then JUnit Test project can be converted from Android JUnit Test project by removing Android Library from project build path, and adding JRE System Library, and JUnit 3 library, and sample test class looks like:
import junit.framework.TestCase;
public class ConverterTest extends TestCase{
public void testConvert() {
assertEquals("one", "one");
}
}
I have had a similar problem, I found it was because I had generated a new activity with a main[] stub entry. Once I deleted the main[] code from the new activity templatye the error went away.
YMMV
This could be a JVM bug; see #Zac's answer. But it could also be that your junit test case is causing a corrupted bytecode file to be loaded. Try rebuilding all your .class files, and if that does not fix the problem try refetching any external libraries that your code depends on.
Do you run on a supported platform (Windows, one of a few Linux versions?) If not, that is the first to try.
If you ARE on a supported platform, then downgrade to _17 and see if THAT helps.
Then make a bug report to Sun and hope they will fix it someday (unless you want to give them money for fixing it faster).
Go to Run As -> Run Configurations->classpath->BootStrap Entries
Click on Advance, then Add Library and select JRE System Library as a first entry.
Apply and Run...
I am not sure whether you were able to reach the solution for your problem or not but your question just popped up while I was searching for the solution for the same problem I am facing. And I got one solution from the stack itself, so just thought to share a link with you if that aids you by any means. The link is as below:
Can't run JUnit 4 test case in Eclipse Android project
Another possible reason (for future references):
I had accidentally copied in a main method in my code, causing Eclipse to recognize the project as a java application, thus launching it with that configuration.
To solve it I went into Run > Run Configurations... and then changed from my presumed main in java application to the main activity of my android application simply by choosing it in the left column.