Asked  7 Months ago    Answers:  5   Viewed   103 times

I creating a program to work with databases and I am getting the following error when compiling in IntelliJ IDEA. Does anyone why this is happening and how I could solve it?

enter image description here

 Answers

93

The error that you get occurs not on complilation, but when you try to run your application. It happens because Java was not able to find Table.class file inside db subdirectory of the project output directory (classpath).

It can happen for multiple reasons:

  • wrong main class selected in the run/debug configuration
  • Table.java is excluded from compilation (by accident or intentionally because it contained errors and you wanted to skip it while working on other code)
  • class not compiled because Build step is excluded from from Before launch steps in the Run/Debug configuration
  • project is misconfigured and there is no Source root defined for the directory containing db subdirectory
  • Table.java has incorrect package statement or is located/moved to a different package
  • project path contains a colon : on Mac/Linux or semicolon ; on Windows, it's used to separate the classpath and will render the classpath invalid. See this thread for details. Note that Finder on Mac may display colons in the path as slashes.
  • the jar may not execute if one of the dependent jars is digitally signed since the new artifact will include the partial signature of the dependency. See this answer for more details.
  • In project structure make sure you have the right Java version for compile.
  • there is a known bug that sometimes a Java project created from the Command Line template doesn't work because .idea/modules.xml file references invalid module file named untitled104.iml. Fix the module name manually or create a project from scratch and don't use a template.
  • on Windows "Beta: Use Unicode UTF-8 for worldwide language support" Region Setting is enabled. See IDEA-247837 for more details and workarounds.
  • When IntelliJ IDEA is configured to store module dependencies in Eclipse format source root configuration is lost due to a known bug. Configure the module to use IntelliJ IDEA format dependencies as a workaround.

In a properly configured project and with the correct run/debug configuration everything works just fine:

Run

Tuesday, June 1, 2021
 
Noob_Programmer
answered 7 Months ago
83

As mentioned in the comments, the Starting Guide is the place to start with Java 11 and JavaFX 11.

The key to work as you did before Java 11 is to understand that:

  • JavaFX 11 is not part of the JDK anymore
  • You can get it in different flavors, either as an SDK or as regular dependencies (maven/gradle).
  • You will need to include it to the module path of your project, even if your project is not modular.

JavaFX project

If you create a regular JavaFX default project in IntelliJ (without Maven or Gradle) I'd suggest you download the SDK from here. Note that there are jmods as well, but for a non modular project the SDK is preferred.

These are the easy steps to run the default project:

  1. Create a JavaFX project
  2. Set JDK 11 (point to your local Java 11 version)
  3. Add the JavaFX 11 SDK as a library. The URL could be something like /Users/<user>/Downloads/javafx-sdk-11/lib/. Once you do this you will notice that the JavaFX classes are now recognized in the editor.

JavaFX 11 Project

  1. Before you run the default project, you just need to add these to the VM options:

    --module-path /Users/<user>/Downloads/javafx-sdk-11/lib --add-modules=javafx.controls,javafx.fxml

  2. Run

Maven

If you use Maven to build your project, follow these steps:

  1. Create a Maven project with JavaFX archetype
  2. Set JDK 11 (point to your local Java 11 version)
  3. Add the JavaFX 11 dependencies.

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11</version>
        </dependency>
    </dependencies>
    

Once you do this you will notice that the JavaFX classes are now recognized in the editor.

JavaFX 11 Maven project

You will notice that Maven manages the required dependencies for you: it will add javafx.base and javafx.graphics for javafx.controls, but most important, it will add the required classifier based on your platform. In my case, Mac.

This is why your jars org.openjfx:javafx-controls:11 are empty, because there are three possible classifiers (windows, linux and mac platforms), that contain all the classes and the native implementation.

In case you still want to go to your .m2 repo and take the dependencies from there manually, make sure you pick the right one (for instance .m2/repository/org/openjfx/javafx-controls/11/javafx-controls-11-mac.jar)

  1. Replace default maven plugins with those from here.

  2. Run mvn compile javafx:run, and it should work.

Similar works as well for Gradle projects, as explained in detail here.

EDIT

The mentioned Getting Started guide contains updated documentation and sample projects for IntelliJ:

  • JavaFX 11 without Maven/Gradle, see non-modular sample or modular sample projects.

  • JavaFX 11 with Maven, see non-modular sample or modular sample projects.

  • JavaFX 11 with Gradle, see non-modular sample or modular sample projects.

Tuesday, June 1, 2021
 
ramdemon
answered 7 Months ago
97

Most likely you have incorrect compiler options imported from Maven here:

compiler options

Also check project and module bytecode (target) version settings outlined on the screenshot.

Other places where the source language level is configured:

  • Project Structure | Project

project

  • Project Structure | Modules (check every module) | Sources

sources

Maven default language level is 1.5 (5.0), you will see this version as the Module language level on the screenshot above.

This can be changed using maven-compiler-plugin configuration inside pom.xml:

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

or

<project>
  [...]
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  [...]
</project>

IntelliJ IDEA will respect this setting after you Reimport the Maven project in the Maven Projects tool window:

reimport

Tuesday, June 1, 2021
 
SilverHorn
answered 7 Months ago
49

IDEA will understand parallel JUnit tests only since version 10.

There is a tracker issue which you can vote for and watch for progress: http://youtrack.jetbrains.net/issue/IDEA-47103

We plan to add it in IDEA 10, but the priority would depend on the number of votes.

Friday, July 30, 2021
 
leetwinski
answered 4 Months ago
10

To make Jest test results shown in a tree view (like karma, etc.), a special integration is needed. WebStorm doesn't yet support Jest. Please vote for WEB-14979 to be notified on any progress.


EDIT: as of March 2017 the first version of Jest integration at WebStorm has been released.

Saturday, October 30, 2021
 
Jon
answered 1 Month ago
Jon
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share