I'm just starting on a large new project, containing the line menuBar = new MenuBar(); MenuBar is packaged in javafx.scene.control. No errors, but when it comes across this line at runtime I get
Exception in thread "AppKit Thread" java.lang.NoClassDefFoundError: Could not initialize class javafx.scene.control.MenuBar
Google suggests there's a discrepancy between my build path and my runtime path. What I'm not sure about is how to actually tell what the build paths and runtime paths are, although I think I have it right.
Build path: I go to
Properties -> Java Build Path
and see that JRE System Library [Java SE 8 [1.8.0_77]] is there. I furthermore confirm that it contains jfxrt.jar. It also detects no errors at build time so I can assume it's working just due to that.
Runtime path: I go to
Run As -> Run Configurations... -> Classpath
and see that JRE System Library [Java SE 8 [1.8.0_77]] is listed in Bootstrap Entries. I don't seem to be able to expand that and confirm that it contains the relevant jar.
Am I missing anything in the runtime classpath?
EDIT: I found another symptom, or a nuance to this. The menuBar = new MenuBar() is contained in the constructor of an object that extends the FX Stage class. The constructor is initialized by clicking a button on a launcher. When I click it the first time, I get a Exception in thread "AppKit Thread" java.lang.ExceptionInInitializerError. The second time I click it is when the NoClassDefFoundError shows up. Does this mean anything?
EDIT 2: Still trying to figure out this problem. I've possibly narrowed it down to an issue with Style. I don't know what that means, really, but the trace may help:
Caused by: java.lang.NullPointerException
at com.sun.javafx.css.StyleManager.getURL(StyleManager.java:867)
at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:1057)
at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:917)
at com.sun.javafx.css.StyleManager._setDefaultUserAgentStylesheet(StyleManager.java:1377)
at com.sun.javafx.css.StyleManager.setUserAgentStylesheets(StyleManager.java:1209)
at com.sun.javafx.application.PlatformImpl.lambda$_setPlatformUserAgentStylesheet$182(PlatformImpl.java:698)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl._setPlatformUserAgentStylesheet(PlatformImpl.java:697)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:548)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
at javafx.scene.control.Control.<clinit>(Control.java:87)
... 6 more
I don't know how to follow past those ...6 more, but I can manually trace through to the JFX MenuBar class to find it in the MenuBar constructor: getStyleClass().setAll(DEFAULT_STYLE_CLASS); seems like a good candidate for where this is happening. I'm not sure how to proceed because this is in the .class file itself. Hopefully this helps.
EDIT 3: I was given the advice to just create a new workspace, check out the projects from SVN, and just start over. The thought was that maybe somehow the workspace was corrupted. Nothing changed; the exact same error has shown up. I am running out of ideas here.
EDIT 4: (thanks for the formatting, Itachi!) Here is what I can show, obscured:
package _______;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import ____.FooMenu;
import ____.FooMenuItem;
import ____.FooUtil;
import ____.FooVBox;
import ____.FooStates;
public class FooStageWithMenu extends FooStage
{
private MenuBar menuBar;
private FooMenu fileMenu;
private FooVBox root;
public FooStageWithMenu(FooStates setting, Image icon)
{
super();
set(setting, icon);
root = new FooVBox();
menuBar = new MenuBar(); //This line is where it fails
root.addNode(menuBar);
/*...*/
}
/*...*/
}
A few other thoughts:
I'm developing on OSX, everyone I've spoken to on the project is using Windows. Could there be an OS-specific source of this problem?
We wanted to eliminate the possibility of library issues, so I installed the most recent version, now running JDK 1.8.0_102, problem still persists.
Is there some chance that even in the most recent JDK, there's some discrepancy between the jfxrt.jars in our respective libraries?
The nature of the specific error (see EDIT 2 above). It seems like there's an attempt to access a style sheet by retrieving a URL, but it either fails in accessing that style sheet, or in getting the URL, or something. Nothing about the NullPointerException seems to help me narrow it down past that. I did explore my jfxrt.jar and found that in the paths the JavaFX classes seem to be searching for, the .css files do exist and seem complete and non-corrupt.
EDIT 5: So I'm pretty sure nobody's reading this, but I did just find a big clue, related to the difference between this version and the previous. I don't think I need to get into the specifics, but this problem is "fixed" by commenting out one line in the launcher class. We have two launcher classes, one of which extends the other. The constructor for the extended class is just super(); new JFXPanel(); If I comment out the second line, it works without any immediately apparent problems. This might be the line that breaks it on a Mac, while it works fine in Windows. I have no idea what this implies, and I have no idea why the original failure I shared was caused by this. But this change is just made in a test branch, so it may be that we have no need to give this problem a proper fix, given the temporary and limited nature. I just wanted to share the update in case it helps anyone else.
Related
The error occurs when I use the library in another library.
Library import is working fine in the app but not working within libraries.
And not able to generate the build of a library.
All libraries are publishable.
Error:
Nrwl.v13 Files Structure within lib folder:
Very difficult to debug. It can be related to circular dependency issue. Are you sure you don't import code from library which import code from the same library ?
A import B
B import A
If this is the case, you should handle this by creating a C library which will be imported by A and B or find a solution for the A or B which will not depend on each other.
Code example will be helpful for help you.
From https://github.com/nrwl/nx/issues/10785#issuecomment-1158916416:
There seems to have been an issue with a migration that was scheduled
for a version but the migration itself was released in another
version, so that might have caused the migration to not run in some
scenarios. That migration should have added the following in nx.json
for anyone having their nx.json extending from
nx/presets/core.json or nx/presets/npm.json:
{
...
"pluginsConfig": {
"#nrwl/js": {
"analyzeSourceFiles": true
}
}
}
Could you please add the above snippet to your nx.json and try again? If after applying the change it doesn't pick
it up immediately, run nx reset and then try again.
This didn't work for me though, so I opened nx issue #11583: library importing other library using wildcard path mapping fails with "is not under 'rootDir'"
I had this issue in one of our monorepo and it was caused by the fact that one of our library's name wasn't valid. We had something like #organisation/test-utils/e2e which we ended up renaming to #organisation/test-utils-e2e (take note of the / usage).
I spent 4 hours, on something simple, trying to figure out why pycharm did not find my pika library when running from inside development environment. The answer became obvious once found but for all you who are suffering from this simple issue try this:
Pycharm -> Run -> Configurations
Uncheck
Add content roots to PYTHONPATH
Add source roots to PYTHONPATH
Run/Debug Configurations
These settings should not result in you not finding the library in your PATH.
It's possible you have files in your project which mirror the names of the library or are otherwise interfering with resolution of the import name. You really should try to fix this issue right here, or you may find yourself having to debug even stranger problems after you send the code along to someone else.
Let's say that you're trying to run :
>>> import foo
This will look for foo.py, or a folder named foo containing __init.py__ in your PYTHONPATH.
If your own code also contains foo.py (or a folder named foo containing __init.py__), python will import your own module instead of the site package you're actually trying to import.
This may seemingly work without error, but if you were instead to do :
>>> from foo import fooclass
This class does not exists in your library, and therefore you're going to get an ImportError.
Similarly, if you did :
>>> import foo
>>> c = foo.fooclass()
You should get an AttributeError
Adding your source roots to PYTHONPATH is a fairly common requirement, and something you may need if your project grows beyond a few files. Not being able to do that can result in some really laborious workarounds in the future.
I'm working on a school project right now, and every time I have in the past, I always make a new Project in IntelliJ IDEA. However, this time she gave us some .class files that have methods in them that we can't see (she described what they do so we know how to use them) but need to use, so they have to be in the same folder, obviously.
SIDENOTE: I'm also new to using Macs, which is what I'm on at the moment.
Anyways, I put the .class files in my src folder that I found in the Project8 folder. I just made an array of the Book objects, which was one of the .class files I moved, and now I need to use a method from the other .class file, named BookInventory.class. I put that file in the src folder just like the other, but it won't let me use the only method in that class, which is LoadBooks.
Here is the LoadBooks signature:
public static void LoadBooks(Book[] b)
And here's the description of it that she gave to us:
"For each element in the array, accepts user input for the book, creates the Book object, and stores the object into the array."
So, when I made the array of Book objects, IDEA made an import statement up top all by itself, I didn't type it:
import java.awt.print.Book;
So why does IDEA recognize the Book.class file and allow me to use it in this .java file for my project, but it doesn't seem to notice the BookInventory.class file?
Any help appreciated, thanks ahead of time.
What is happening is when you first typed the line with LoadBooks(Book[] b), IntelliJ could not "see" your class files (you have subsequently loaded them in "class files" and added that as a project library, I presume).
IntelliJ however searched for and found a Book class in the internal java libraries, java.awt.print.Book. Note that this is a different class to the one your teacher gave you, which might have been e.g. edu.myschool.homework.Book.
Firstly, try to delete the line including the import statement, or manually change it to the correct package (your teacher can inform you what it is).
If the same import comes back automatically, you can go into Settings -> Editor -> General -> Auto Import and untick Add unambiguous imports on the fly - this will cause intellij to prompt you before adding imports.
Also, I would ask your teacher to give you the class files in a jar file, since that's the usual approach.
Good luck.
Today I cleared my .ivy cache and cleaned my project output targets. Since then I have been getting really strange behaviour when running tests with SBT or editing in the Scala IDE.
Given the following:
package com.abc.rest
import com.abc.utility.IdTLabel
I will get the following error:
object utility is not a member of package com.abc.rest.com.abc
Notice that com.abc is repeated twice, so it appears that the compiler uses the context of the current package when doing the import (maybe it's supposed to do this, but I never noticed it before).
Also, if I try to access classes in package com.abc from anywhere inside com.abc.rest (even using the full path) the compiler will complain that the type can not be found.
It appears that the errors only occur when I try to include files from parent packages. What I do find strange is that my code used to work. It only started happening after I cleaned up my project and my ivy cache, so maybe a later version of the compiler is more strict than the previous one.
I would love some ideas on what I can be doing wrong, or how I can go about troubleshooting this.
Update:
By first importing the parent classes and then defining the current package, the problem goes away:
import com.abc.utility.IdTLabel
import com.abs._
package com.abc.rest {
// Define classes belonging to com.abc.rest here
}
So this works, but I would still love to know why on earth the other way around worked, and then stopped working, and how on earth I can fix it. I had a good look, and could find no packages, objects or traits by the name of com anywhere inside the parent package.
Update relating to Worksheets:
Scala worksheets belonging to the same package share the same scope, which sounds obvious, but wasn't. Worksheets are not sand-boxed - they can see the project, and the project can see them. So all the 'test' object, traits, and classes you create inside the worksheet files, also becomes visible in the rest of the project.
I have so many worksheets that I did not even try to see where the problem came in. I simply moved them all to their own package, and like magic, the problem went away.
So, lesson learned for the day: If you create stuff inside worksheets, it's visible from outside the worksheet.
Anyway, this new found knowledge will come in handy, meaning anything 'interesting' can be build, monitored and tweaked inside the worksheet, while the rest of the project can actually use it. Quite cool actually.
It's still interesting to think how a sbt clean and cleaned up ivy cache managed to highlight the problem that was hidden before, but hey, that's another story....
(At the request of JacobusR, I'm making a proper answer out of my earlier comments).
This can happen if you have defined some class/trait/object inside package com.abc.rest.com. As soon as package com.abc.rest.com exists, and given that you are in package com.abc.rest, com would designate com.abc.rest.com as opposed to _root_.com. Fastest (but non-conclusive) way to check, without even scanning the source files, is to look for any .class files in the "com/abc/rest/com" sub-folder.
In particular you would get this behaviour if any of your files has duplicate package definitions (as in package com.abc.rest; package com.abc.rest; ...). If you have this duplicate package clause somewhere in the same file where you get the error, you wouldn't even see anything fishy with the .class files, as the failure at compiling the file would prevent the generation of .class files for any class definition inside the file.
The final bit of useful information is that as you found out the scala Worksheets are not sandboxed, and what you define in the worksheets affects your project's code (rather than only having the project's code affecting the worksheet). So a duplicate package clause in a worksheet could very well cause the error you got.
If package names conflict, there might be a custom error message for that. See if specifying the full path resolves the issue by starting from __root__. Ex. import __root__.com.foo.bar._
My program is just a simple System.out.println("");
But netbeans cannot find the main method.
Is netbeans 6.7.1 conflict with WIN7?
Any possible error?
This happens when you move your main class location manually because Netbeans doesn't refresh one of its property files.
Open nbproject/project.properties and change the value of main.class to the correct package location.
Sometimes passing parameters in the main method causes this problem eg. public static void main(String[] args,int a). If you declare the variable outside the main method, it might help :)
Exceute the program by pressing SHIFT+F6, instead of clicking the RUN button on the window.
This might be silly, bt the error main class not found is not occurring, the project is executing well...
It was most likely that you capitalized 'm' in 'main' to 'Main'
This happened to me this instant but I fixed it thanks to the various source code examples given by all those that responded. Thank you.
This destroyed me for a while.... I knew that there HAD to be an easier way with a world class IDE like Netbeans.
The easiest method is to press Shift+F11 (Clean and Build Project), then hit F6 to run it.
It refreshes Netbeans appropriately and finds your main without all the manual labor; and if you have multiple mains, it will give you the option to select the correct one.
Make sure it is
public static void main(String[] argv)
No other signature will do.
in Project window right click on your project and select properties go to Run and set Main Class ( you can brows it) . this manual work if you have static main in some class :
public class Someclass
{
/**
* #param args the command line arguments
*/
public static void main(String[] args)
{
//your code
}
}
Netbeans doesn't have any conflict with W7 and you can use version 6.8 .
If you named your class with the keyword in Java, your program wouldn't be recognized that it had the main method.
I had this issue as well (Error: Could not find or load main class test.Test). I'll explain this relatively basically since I know I would have appreciated someone doing that when I was looking for my answer.
When I right-clicked on the project (left hand side of the screen unless you got rid of the projects tab) and went to properties and then run, the main class had the projectname.classname, which is what confused me.
For example, I created a project "test" to test this out, and when I went to
(right-click) test or Source Packages -> properties -> run -> main class
had Test.test in that field, which is what the problem was. the class is test, not Test.test, so I clicked browse to its right, and the only thing in the list to select from was test, and when I selected that and tried rerunning it, it finally worked.
Additionally, I found that when you create a new project in Netbeans, one of the things it originally gives you (in my case of the project named test) is package test;. If you are having this problem, then like me, you probably originally got rid of that line seeing it as just another line of code you didn't need. That line of code is what enabled your main class which in my case was Test.test to find the main class *test from that.
My situation was different I believe because non of the above solutions di work for me. Let me share my situation.
I am importing an existing project (NewProject->Java->Import Existing Projects)
I name the project to xyz. The 'main' function exists in Main.class.
I try to run the code I modified in the main function but the error pops out. I tried the shift_f6, specifically rebuild. Nothing works.
Solution: I took the project properties and saw the 'Source Package Folder' mappings in the Sources branch was blank. I mapped it and voila it worked.
Now anyone might think that was very silly of me. Although I am new to Java and Netbeans this is not the first time I am importing sample projects and I saw all of them had the properties similar. The only difference I saw was that the main class was not having the name as the project which I believe is a java convention. I am using JDK7u51 (latest till date), is it causing the issue? I have no idea. But I am happy the project is running fine now.
Check for correct method declaration
public static void main(String [ ] args)
Check netbeans project properties in Run > main Class
While this may be an old question, the problem is still occurring these days, and the exact question is still not answered properly.
It is important to note that some projects have multiple classes with a main method.
In my case, I could run the project via the main class, but I could not run a particular other class that had a main method.
The only thing that helped me was refactoring the class and renaming it.
I've tried:
restart NetBeans
re-open the project
clear NetBeans cache
delete the file and create a new one with same name and contents
delete the file and create a new one with same name but very simple contents with only main method and print out message
rename the class (refactor) so a temp name and back
delete the project and create a new one with the same sources
The only thing that let me run this class is renaming it permanently. I think this must be some kind of a NetBeans bug.
Edit: Another thing that did help was completely uninstall Netbeans, wipe cache and any configuration files. It so happened that a newer Netbeans version was available so I installed it. But the old one would have probably worked too.
public class TestConnection {
public static void main(String args[]) {
//make sure when you create a new class, it has the above line, and then
//when you click shift+F6, it works fine for NetBeans IDE 12.4
myConnection my = new myConnection();
my.getConnection();
}
}