When I try to make a project in IntelliJ I receive the following error on this line:
Sentence sent = new Sentence();
sent.emptySegments();
Error:
Error:(151, 10) java: cannot access javax.xml.bind.RootElement
class file for javax.xml.bind.RootElement not found
Sentence is a class which implements the RootElement interface
import javax.xml.bind.RootElement;
...
public class Sentence extends MarshallableRootElement implements RootElement {
All packages exist and I can jump to declaration of each interface or class but I don't know why IntellJ says it cannot access or find them? However RootElement is an interface and not a class
public interface RootElement extends Element {
void validate() throws StructureValidationException;
}
The above declaration is in a jar file named jaxb-rt-1.0-ea.jar and it exists in the Project librarians.
Try this
Go to File
Invalidate Caches/Restart
You can choose only Invalidate and restart
(See Invalidate caches on IntelliJ's manual)
The project contained several modules. While the library was added to the project libraries, some modules lacked it in their dependency part. So I solved the problem using the following steps in IntelliJ
Creating a module library and adding it to the module dependencies:
Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
In the left-hand pane of the dialog, select Modules.
In the pane to the right, select the module of interest.
In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
On the Dependencies tab, click + (on the top right) and select Jars or directories.
In the dialog that opens, select the necessary files and folders. These may
be individual .class and .java files, directories and archives
(.jar and .zip) containing such files as well as directories with
Java native libraries (.dll, .so or .jnilib).
Click OK. If necessary, select the Export option and change the dependency scope.
Click OK in the Project Structure dialog.
File -> Invalidate Caches/ Restart
this worked for my after long hours of effectiveless
Rebuilding project worked for me.
Deleting the .idea folder and then running Invalidate Caches/Restart worked for me.
It also may be because you don't have dependencies in classpath, which used in dependencies.
For example: you use library A, but class you're using from A has superclass from library B. But you didn't add B to classpath.
If it is a single file, you can try deleting the file and undoing it. It seems to reindex that particular file alone, which is much faster than Invalidate Caches/Restart. As a precautionary measure, you can take a backup of the file before deleting, just in case if something goes awry.
Another reason might be different versions of same library with more/less methods. This happened for me with Gradle. Sometimes it compiles fine and sometimes, it doesn't. Just find and remove the unnecessary ones.
My Gradle/IntelliJ "big hammer"
(Optional, but preferred). Close all instances of IntelliJ or any other Java IDE.
delete the ".idea" folder (<< intellij specific, or whatever "workspace" folder your IDE uses)
..............
./gradlew --stop
OR
gradle --stop
(now delete the folders)
rm -rf $HOME/.gradle/caches/
rm -rf $HOME/.gradle/build-cache-tmp/
(now resume normal gradlew commands like:)
./gradlew clean build
For me just worked, turn off windows defender / add exclusion project folder / idea process.
Similar problem can happen if a library is imported with maven scope runtime.
In such case it isn't accessible by your classes located under src/main/java.
Only classes in src/test/java can directly use runtime dependencies.
I removed this location "amazonaws" file and clean install later run
/Users/testuser/.m2/repository/com/amazonaws
If you've made it this far because rebuilding or invalidating the cache didn't work work you, I found that deleting the class and adding a new one with the same code worked.
In my case there was an old .iml file in the module causing these problems. So if nothing else worked for you, try looking for one.
⬇ Download the last version of IntelliJ.
▶ Install it.
Worked for me. ✌
Related
So I'm making a java application in Neatbeans 7.4, been working at it for a while, everything was fine, running the project worked fine, but now when I hit run project, I get the error
Error: Could not find or load main class phleveledit.MainWindow
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
I can't think of what I did right before this started happening, so I don't know what I should change.. The code doesn't appear to have any errors. Here's a screenshot of the IDE+project folder
Image (http://puu.sh/5ldYB) :
Any ideas?
Edit: Unfortunately I happened to fix this problem by removing some code, which probably had some errors Netbeans couldn't detect, but I don't know what was exactly wrong so can't vote on a correct answer.
Right click on your Project in the project explorer
Click on properties
Click on Run
Make sure your Main Class is the one you want to be the entry point. (Make sure to use the fully qualified name i.e. mypackage.MyClass)
Click OK.
Clean an build your project
Run Project :)
If you just want to run the file, right click on the class from the package explorer, and click Run File, or (Alt + R, F), or (Shift + F6)
Just close the Netbeans. Go to C:\Users\YOUR_PC_NAME\AppData\Local\Netbeans and delete the Cache folder. The open the Netbeans again and run the project.
It works like magic for me.
(AppData folder might be hidden probably, if so, you need to make it appear in Folder Options).
You can :
RightClick on project node and go to Set configuration
Select the main class for your application.
Then clean and build.
Even if the above steps don't work for you then then delete the Netbeans cache by deleting the (index) folder
User\.netbeans\SOME_NUMBER_reflecting_your_version\var\cache\index\
Sometimes due to out of memory space error, NetBeans does not load or find main class.
If you have tried setting the properties and still it is not working then try
Select the project from the project explorer
Click on Run in the Menu Bar
Click on Compile
It worked for me.
This condition happens to me every 6-months or so. I think it happens when closing NetBeans under very low memory conditions. I discovered that it could be easily corrected by (1) Rename your project, including its folder name using right-click on project explorer's project name---I put a simple suffix on the original name ("_damaged"). (2) Try BUILD. If that is successful, which it is for me, give three cheers. (3) Repeat step (1) to restore the original project name. BUILD and RUN should start without trouble.
I guess that the 'rename the project and folder' process causes a special rediscovery of the applications main location.
Try to rename the package name and the class/jframe names... The clean and build the application.
Right Click on the package name
Go to Refactor
Select Rename
Give it a meaningful name, preferably all in small letters
Click on Refactor
Do the same for the class/jframe names.
Last Select Run from Menu
7.Select Clean and build main project
That should do it!!! All best
I had the same issue once. The problem was not in the code. The cause was... renaming the project folder to some other non supporting name. My project name was "MobStick" and I renamed it to "MobStick - May 26, 2014 04:00PM". Renaming it back to normal solved my problem.
I have run into this error a couple of times as well and for me the above solutions did not work. What does seem to work is going to the Project Properties, and under Compiling toggling Compile on Save.
Using NetBeans 8.1, I got the dread
Error: Could not find or load main class
from carelessly leaving an empty line in the Project Properties > Run > VM Options field. Until you click in the field, you may not see the caret flashing out of place. Remove the empty line to restore equanimity.
I just ran into this problem. I was running my source from the command line and kept getting the same error. It turns out that I needed to remove the package name from my source code and then the command line compiler was happy.
The solutions above didn't work for me so maybe this will work for someone else with a similar problem.
I had the same problem, I had the package and class named the same. I renamed the class, then clean and build. Then I set the main class in the "run" under the properties of the project. I works now.
I found the following steps useful:
Right-click on the project in the left toolbar.
Hover over the 'Set Configuration' item.
Click on 'Customize...'
Click on 'Browse...' by the 'Main Class:' item.
Select the correct class.
Click 'Select Main Class'.
Click 'OK'.
My problem was that, apparently, my package name was being listed twice. Selecting the class using the dialog changed 'aclass.MainClass' to just 'MainClass'.
Hope this helps,
-HewwoCraziness
Edit: This is expanding on Mary Martinez's answer.
You can solve it in these steps
Right-click on the project in the left toolbar.
Click on properties.
Click on Run
Click the browse button on the right side.(select your main class)
Click ok
Possible Fixes:
Fix 1
Go to project properties (right click on the folder of your project in netbeans)
On left tab where it shows the categories, click on the "Run" selection
Then click on Browse to find the Main class you use on your project
Fix 2
Go to C:\Users\name\AppData\Local\Netbeans
delete the Cache folder.
Rebuild and Run
Fix 3
Download most recent version of Netbeans
Fix 4
Download most recent version of JDK and configure Netbeans to use that
I had the same problem for 3,4 days. On my PC my Jar file snapshot would give me this error while on my laptop it would work fine, I tried all the tricks shown above and on other forums like deleting cache, selecting main project file, etc, but somehow I was sure the reason it cannot find the main class when I would execute the JAR file was may be due to classpath issue in maven configuration, and I was right and I fixed it using following steps:
Right-click on the project, and go to the properties
Inside the properties go to Actions
On the right side in Actions select "Run Project" and you will see properties below
Inside "Set Properties" make sure exec.args=classpath %classpath "package_name"
In my case, the package name was accompanied by the main class. So my main class was Login while the package name was com.mycompany.islamic_center_app1, When I checked the entry was
com.mycompany.islamic_center_app1.Login
All I did was remove ".Login" from com.mycompany.islamic_center_app1 and it was fixed, no more errors.
close netbeans.
open netbeans again.
choose new project>>java application.
click next.
deselect create main class.
now make the application
clean build run
For more reference watch this video
try this it work out for me perfectly
go to project and right click on your java file at the right corner,
go to properties,
go to run,
go to browse, and then
select Main class.
now you can run your program again.
I had the same problem and I moved the project to a location where the path had no none-english letter and that fixed the problem
if you are on window os, then try to start NetBeans via administrative mode. right click on NetBeans icon and "Run as Administrative".
If none of the above works (Setting Main class, Clean and Build, deleting the cache) and you have a Maven project, try:
mvn clean install
on the command line.
Had the same problem here. Usually Clean and Build solves much of the problem. It happened to be caused by a wrongly installed plugin.
I faced the similar issue with Netbeans 10 and JDK 1.8.
I was not able to choose the right class to launch the project
When I compile or run the project, it shows me the Class name as "initializing view, please wait ...", I could not select the class name.
The issue was resolved with the NetBeans11.3, I am able to choose the correct Class file without any other changes, and the project is launched without any issues.
I had the same issue but none of this thread's solutions worked for me. Finally, it was OneDrive that caused the issue (for once more). So, I simply moved the NetBeansProjects folder from Documents which is synced with OneDrive, to C:\Users\yourName\AppData\Local\NetBeans (selected this path as there is already a NetBeans folder) and that was it, case closed.
If you also have NetBeansProjects to a OneDrive syncing folder it is worth trying this solution, just be sure that the path you will select is not synced with OneDrive. Also, remember to close Netbeans before making the folder change and after you move the folder to the new path you need just to open Netbeans again, go to file menu/open project and select your project from the new path.
I'm following one of the play framework tutorials, but I'm getting compile errors whenever I try to use reverse routing. Firstly,
public static Result javascriptRoutes() {
response().setContentType("text/javascript");
return ok(
Routes.javascriptRouter("jsRoutes",
controllers.routes.javascript.Projects.add(),
controllers.routes.javascript.Projects.delete(),
controllers.routes.javascript.Projects.rename(),
controllers.routes.javascript.Projects.addGroup()
)
);
}
where the error shown in intelliJ is 'cannot resolve method javascriptRouter(java.lang.String, ?, ?, ?, ?)'
But also in the a unit test:
#Test
public void notAuthenticated() {
Result result = callAction(
controllers.routes.ref.Application.index(),
fakeRequest()
);
assertEquals(303, status(result));
assertEquals("/login", header("Location", result));
}
where it cannot resolve the index method.
Is this a problem with intelliJ, or am I missing something within play?
For the first part, here is the entry in my routes file:
GET /assets/javascripts/routes controllers.Application.javascriptRoutes()
and my controller, Projects, has got the defined methods.
File -> Project Structure
Select Sources in Right Pane
Add Source folder
target/scala-XXX/classes_managed
target/scala-XXX/src_managed/main
I was running into the same problem and found the solution here: https://github.com/playframework/Play20/issues/969
In short:
Create the directories javascript and ref under the controllers package
Run activator compile and now Intellij should get it // used to be 'play compile'
If you still got the errors try to run activator idea again // used to be 'play compile'*
Pulled from a link provided by #Markus Kittig. Great temporary fix. https://github.com/playframework/playframework/issues/1784#issuecomment-26345523
Synopsis:
Add target/scala-XXX as a managed source and remove the app controllers and views sources flag inside File->Project Structure->Modules->Sources. Then recompile.
Works on IntelliJ Ultimate 12.1.{4|6}. Created the play application with the command line interface and generated a project file using play idea. Used Play 2.2.0.
With IntelliJ 14.1 and Play 2.3.8 nothing of the above worked, but the advice from this mailing list worked. (Almost) blatantly copied:
Locate the target/scala-2.11/src_managed and target/scala-2.11/twirl
directories in the project view, then right click and Mark Directory
As -> Generated Sources (Root).
I bumped the scala version and obviously in newer versions of IntelliJ the Root word has been added. Also, you cannot select this from the Project Structure window, the option is not available. It is possible only through the Project pane in the main window. If it refuses to be marked as Generated Sources, try to unmark thetarget directory (Mark Directory As -> Unmark ).
For people using Play 2.4.x or above, it seems that Play no longer produces reverse routing files for javascript in src_managed et al.
Instead, you need to include scala-2.xx/routes/main directory as Sources.
This question was asked a year ago, but to answer for future queries by other coders, the problem is easily solved by adding a "play.Routes" path like this
public static Result javascriptRoutes() {
response().setContentType("text/javascript");
return ok(
play.Routes.javascriptRouter("jsRoutes",
// Routes for Projects
controllers.routes.javascript.Projects.add(),
controllers.routes.javascript.Projects.delete(),
controllers.routes.javascript.Projects.rename(),
controllers.routes.javascript.Projects.addGroup()
)
);
}
Ensure that you have the proper imports to the class:
import play.mvc.*;
import play.data.*;
I am using Idea 14.1.4 community edition, i managed to remove the index and route not resolved errors by right clicking on the target folder and marking it as not excluded. NB i run my project using the command line i can not find any run configuration in the ide.
I didn't find that folders in my PLay 2.8 build, so as it was a problem with IntelliJ I found an easier solution:
https://stackoverflow.com/a/70339356/2367237
I'm working on a simple JSP/Servlet/Tomcat webapp for my class. The professor asked us to use a folder structure that is slightly different than the default dynamic web project structure. Rather than using the webcontent folder he wants all of our source code under src/main/java and src/main/webapp.
When I run the app my welcome file displays fine, but when I try to access my servlets I get:
Http 500 SEVERE: Allocate exception for servlet InitDb
java.lang.ClassNotFoundException. I'm pretty sure it's a build path error. I have final/src on the build path but I am receiving the warning
"Cannot nest 'final/src/main/webapp/WEB-INF/classes' inside 'final/src'. To enable the nesting exclude 'main/' from 'final/src'
I have this in my deployment assembly:
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
When I exclude main/ the warning goes away, but it doesn't fix the problem. I would appreciate any advice. Thanks.
I had the same problem even when I created a fresh project.
I was creating the Java project within Eclipse, then mavenize it, then going into java build path properties removing src/ and adding src/main/java and src/test/java. When I run Maven update it used to give nested path error.
Then I finally realized -because I had not seen that entry before- there is a <sourceDirectory>src</sourceDirectory> line in pom file written when I mavenize it. It was resolved after removing it.
I wanted to throw in a non-mavenish answer to this thread.
Due to version control and strict directory structure reasons, I was unable to follow Acheron's answer (the best answer) of doing something similar to removing src/ and adding src/main/java and src/test/java to the build path.
I had actually been off-and-on battling this nested build path issue for a couple weeks. The answer to the problem is hinted in the error message:
To enable the nesting exclude 'main/' from 'final/src'
Fix
In your build path, you need to edit your Inclusion and Exclusion Patterns by clicking on Excluded: (None) and then Edit...:
Go to the navigator and press right click on the project
Build Path
Configure Build Path
Source (tab)
There you can add main/webapp/WEB-INF/classes as an Exclusion Pattern. Then it should allow you to add main/webapp/WEB-INF/classes to the build path as a separate source folder.
Here is a simple solution:
Right click the project >> properties >> build path;
In Source tab, Select all the source folders;
Remove them;
Right click on project, Maven >> Update the project.
Try this:
From the libraries tab:
Eclipse -> right click on project name in sidebar -> configure build path -> Libraries
Remove your web app libraries:
click on "Web App Libraries" -> click "remove"
Add them back in:
click "Add Library" -> click to highlight "Web App Libraries" -> click "next" -> confirm your desired project is the selected option -> click "Finish"
Highlighting "Web App Libraries":
I had the same issue and correct answer above did not work for me. What I did to resolve it was to go to Build Path->Configure Build Path and under the source tab I removed all the sources (which only had one source) and reconfigured them from there. I ended up removing the project from eclipse and import the maven project again in order to clear up the error.
In my case I have a gradle nature project in eclipse, the problem was in a build.gradle, where this sourceSets is specified:
sourceSets {
main {
java {
srcDir 'src'
}
}
}
This seems to works well with intelliJ,however seems than eclipse doesn't like nest src, src/java, src/resources. In eclipse I must change it to:
sourceSets {
main {
java {
srcDir 'src/main/java'
}
}
}
You have to separate your sources and your target directory where the build output goes. It's also important to note that no class files ever can end up in the source directory. This is not against your professor's advice - actually he's promoting the maven standard source structure going for ./src/main/java and ./src/main/webapp. The second one should hold eg. the mandatory WEB-INF/web.xml file but you will never put actual classes there.
What you need to change is your target directory. I suggest going with the same standards and choosing the name "./target" for this. All the built files will go in here and packaging that up will result a correct deployable artifact. Should you migrate to using maven later, it'll also help doing this in a scripted, repeatable way.
Hope that clears up your issue.
The accepted solution didn't work for me but I did some digging on the project settings.
The following solution fixed it for me at least IF you are using a Dynamic Web Project:
Right click on the project then properties. (or alt-enter on the project)
Under Deployment Assembly remove "src".
You should be able to add the src/main/java. It also automatically adds it to Deployment Assembly.
Caveat: If you added a src/test/java note that it also adds it to Deployment Assembly. Generally, you don't need this. You may remove it.
This started taking me down a huge rabbit hole of fixing glitches with Eclipse, however I just deleted the project from Eclipse and reimported it to fix it.
Got similar issue. Did following steps, issue resolved:
Remove project in eclipse.
Delete .Project file and . Settings folder.
Import project as existing maven project again to eclipse.
For Eclipse compiler to work properly you need to remove final/src from the source path and add final/src/main/java instead. This may also solve your problem as now the build directory won't be inside the Java source folder.
It depends on which folder one is telling "Use as Source Folder" to. In the structure on the picture if one says it to the folder "target" or "generated", he gets the "nested" error. But on "cxf" folder, which is the last, mentioned in the pom.xml's 'plugin' section and where from the package structure begins (as shown on .wsdl file), i.e. - the right folder to do it 'source' one, then there is no error
If other solutions did not work and you are using any plugin adding sources in your pom.xml check it. I used build-helper-maven-plugin to add classes generated from openapi specification with incorrect configuration:
<source>${project.build.directory}/generated-sources/openapi/src</source>
instead of correct:
<source>${project.build.directory}/generated-sources/openapi/src/main/java/</source>
So after correcting:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/openapi/src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Make two folders: final/src/ to store the source java code, and
final/WebRoot/.
You cannot put the source and the webroot together. I think you may misunderstand your teacher.
I am attempting to incorporate admob ads in my app. So far I have added the following code
in the onCreate method of my app's main activity...
adView = new AdView(this,AdSize.BANNER,"my code number");
adView.loadAd(new AdRequest());
The program compiles without error but at run time I get the message java.lang.NoClassDefFoundError: com.google.ads.AdView. I have seen a supposed explanation of the problem and the cure here but I could not see how it was applicable to my project because I do not have either a "lib" or "libs" directory within my project.
According to eclipse's SDK manager, I have the most up to date version of everything that I use.
I had a similar problem, but did not have to add the libs folder; I tried, with no success, then removed them afterwards, when I realized that I had just forgotten to export the included Jar archived.
Fix:
Select project settings > Java Build Path, then Order and export.
Here, check the GoogleAdMobAdsSdk-package.
This should solve the NoClassDefFoundError-issue.
Just create manually the "libs" folder, and add your libraries there. By default, they doesn't exist
Project-> Clean
Project settings -> Java Build Path. Open "Order and export" tab.
Check GoogleAdMobsAdsSDK.
It is worked for me.
Was getting this error updating from android 16 to 20.
Solved by going to Java Build Path, Order and Export tab, checked and moved GoogleAdMobAdsSdk just under my source. For some reason that fixed it.
Changing the order back didn't break it. So some setting must have needed to be initialized.
I had this problem, and this problem too:
Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode and Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode
Despite many hours of following all solutions listed the only way I could get my app to work was to use the AdMob banner example here:
https://github.com/googleads/googleads-mobile-ios-examples/tree/master/admob/SmartBannerExample
And re-build my project around it, copying my files in to that project. If you are stuck, try it.
Don't know why it worked, but now it does. Something in my project was very wrong. Now I can carry on with my work. I love Google/Android, but really what a mess!
See this answer Android update 17 seems incompatible with external Jars.
You need to put all jars in libs folder insted of lib.
It's not enough only to add "GoogleAdMobAdsSdk-6.4.1.jar" in Java Build Path,then you should switch to table:Order and export.check the "GoogleAdMobAdsSdk-6.4.1.jar" here.
UPDATE:
Select project settings > Java Build Path, then Order and export.
Here, check the google-play-services.jar.
This should solve the NoClassDefFoundError-issue.
In my case I needed to click on the "Android Private Libraries" on the "Order and Export" Tab
Go to Properties - Java Build Path - Order and Export and check every Checkmark! That did the trick for my project.
My Eclipse (Indigo) was running just fine. I created a simple class Hello. It is placed in package cont in the folder ch13. However, when I try to run it from Eclipse I get info from Java Virtual Machine Launcher:
Could not find the main class: cont.Hello.
I tried to run other classes from this package and they run just fine (that is the classes that existed there before). However any new class I create in this package has these problems. Actually any new class I create in Eclipse runs into this problems. I decided to check how it works from the command line. It seems that the problem still exist - I get same error. I checked the path and it is C:\Program Files\Java\jdk1.7.0_02\bin, which is correct (note the other classes are running from Eclipse just fine). I tried to run with java -cp . Hello and there are some Errors produced starting with java.lang.NoClassDefFoundError: Hello (wrong name: cont/Hello). Code itself is simple:
package cont;
public class Hello {
public static void main(String[] args){
System.out.println("Hello");
}
}
How can I fix it so that my classes still run under Eclipse?
.metadata is corrupted.
Steps:
Warning: Deleting .metadata will delete all your Eclipse configurations, plugins, project setups. Make a backup before you attempt this!
Stop eclipse, delete .metadata in workspace and restart eclipse
Import Project
Run again
Removing the Run Configuration
Sometimes I have a similar problems in some pre-release versions of eclipse. For fix the error, I delete the Run Configuration. You can find that in menu Run, Run Configurations...
Then I launch the app with Alt+Shift+X, then J. If this don't work, Ctrl+F11.
Deleting the .metadata directory
In another way, the configuration settings for your current workspace may are corrupted. Those settings are in the .metadata directory in your current workspace 1. In that case, there is no other choice than delete the directory:
Close eclipse.
Delete the .metadata directory.
Start eclipse.
Import the projects.
Run the project again.
Notes
You will see that directory with File > Switch Workspace > Other...
I have solved the issue following way:
Go to Run Configuration (Right Click on Java File->Run->Run Configuration).
Go to ClassPath Tab:
Click on Advanced -> Add Folders -> Add bin directory (which has class file in it for Java source code)
Re run the code, now it will solve the issue. It worked for me
Note: This worked in the past and I received many up votes. Perhaps this is not a solution anymore - but it once was - as the eclipse version was indicated.
Problem
This can also be caused by a Java Build Path Problem.
In my case, I had a an error:
A cycle was detected in the build path of project {project}. The cycle consists of projects {x, y, z}.
This can occur when you include other projects in the build path of the project you wish to run. In fact, all the projects will fail to run with the error
Could not find the main class: Example.class
Solution
Open
Windows -> Preferences -> Java-> Compiler -> Building -> Build Path Problems
Uncheck the Abort build when build path errors occur toggle
This seems like a can of worms if you end up with other build path errors I image. So use with caution.
Note: This only works if you have a "cycle error". This error message can be found in the "Markers" tab
I found the solution to this here
Info
Java 1.8.0_152
Eclipse Photon (June 2018)
Renaming the main class should be enough (and easiest):
- Go to your class and set cursor to your class name;
- ALT + Shift + R and rename the class (build if not done automatically);
- You should be able to run it now;
- Rename the class to the old name if you want;
You must have main function in your class. Like
public class MyDataBase {
public static void main(String args[]) {
}
}
I had this same problem in a Maven project. After creating the src/test/java folder within the project the error went away.
Another tip: I initialized static fields in a wrong order - surprisingly it didn't bring up a Problem (NullPointerException?), instead Eclipse complained with exactly the message OP posted. Correcting the static initialization order made the class run-able. Example:
private static ScriptEngineManager factory = null;
private static ScriptEngine engine = null;
static {
engine = factory.getEngineByName("JavaScript");
// factory is supposed to initialize FIRST
factory = new ScriptEngineManager();
}
I found the way to fix this problem was to rename the project. If you give it a name with strange characters (in my case, :), it will have trouble locating your class. I don't know if this rule applies to numbers, but try renaming the project or making a new one and copying the files. Name it without any numbers or special characters.
I solved this error by closing the project, removing it from eclipse and then importing it again.
Might be a little simpler than to redo the whole workspace setup.
I had this issue after upgrading to the Eclipse 2019-12 release. Somehow the command line to launch the JVM got too long and I had to enable the jar-classpath option in the run configuration (right click on file -> run as -> run configs).
I read so many blogs and tried so many tricks but my problem not resolved. I was able to run the code but not able to generate the jar file. :( Sad..
But I tried something which might be very silly but worked for me and bought eclipse on trace. What I did was..
Just deleted the main method from the class. Saved it. Did undo to bring the main class back. Tada... Issue resolved...
Just one think would like to say, keep your eclipse in "Build Autometically" mode.
Move your file into a subdirectory called cont
Standard troubleshooting steps for Eclipse should include deleting and re-importing the project at some point, which when I have dealt with this error has worked.
I solved my issue by doing this:
cut the entire main (CTRL X) out of the class (just for a few seconds),
save the class file (CTRL S)
paste the main back exactly at the same place (CTRL V)
Strangely it started working again after that.
It is possible to have 2 groovy-xxx-all.jar files by excample in lib directory. which makes that an app is not running
I had the same problem, this is my solution:
I manually deleted the bin folder of the project
Then I refreshed the project which recompiled the whole project and created a new bin with all .class files
I did it because when I performed Clean(project->clean) my .class files were not getting deleted. the above solution works for me hope its useful to others.
I had the same problem.I solved with following command maven:
mvn eclipse:eclipse -Dwtpversion=2.0
PS: My project is WTP plugin
If you are using a pre-defined run configuration, go to classpath and try "Restore Default Entries". This will reconfigure the classpath for that configuration.
This worked for me finally :
RUN -> RUN CONFIGURATIONS -> DELETE THE RUN CONFIGURATION
CLOSE ECLIPSE
REOPEN ECLIPSE
CREATE RUN CONFIGURATION AGAIN.
Tadaaaa !! It works