1

This is the code I'm unable to run in IntelliJ:

package hjemmestud.grafikk;

public class Grafikk extends EasyGraphics {

    public static void main(String[] args) {
        launch(args);
    }

    public void run() {
        this.makeWindow("Grafikk", 300, 300);
        this.drawCircle(150, 70, 60);
        this.drawCircle(150, 190, 60);
    }
}

It's supposed to create two circles on top of each other in a small window, like this: Program Example

Current file structure, IntelliJ Project folder: File Structure

Website of downloadable JAR file (second file): https://dbsys.info/programmering/easygraphics/nedlasting.html

I've successfully run the program using just Windows CMD with a different folder structure: File Structure using CMD (before compiling) I did this by running these two lines of code in CMD:

javac -classpath .;.\easygraphics.jar Grafikk.java

java -cp .;.\easygraphics.jar Grafikk

However, when I transfer the files to IntelliJ, it doesn't seem to work. I've tried having the JAR file on the same level as the Grafikk.java class, on the same level as hjemmestud.grafikk package and in the same level as the src folder, both just the JAR file itself and in a lib folder, but none of it has worked.

I've also of course added the path to the JAR file in the external libraries by modifying the Project Structure, in the Libraries and Modules for each time, but I still get errors up saying it cannot resolve the symbol 'EasyGraphics'.

I've also tried reloading the project from disk and rebuilding the project, aswell as editing the configurations of the class file, without any luck.

Datanerd
  • 21
  • 5
  • Please provide the [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) (shared sample project to reproduce the issue). – CrazyCoder Jul 13 '23 at 19:05
  • 1
    I checked the jar and all the classes in this jar are in the default package. Java cannot import from the default package when your class is in the named package: https://stackoverflow.com/questions/283816/how-to-access-java-classes-in-the-default-package. – CrazyCoder Jul 14 '23 at 00:36
  • I see! I was not aware of this, thank you for the information! I moved the lib folder containing the jar into the src folder, and the Grafikk.java class into into the src as well, and it finally worked. Maybe not the perfect way to do it, should I improve it further? – Datanerd Jul 14 '23 at 00:54

1 Answers1

1

It was as user "CrazyCoder" commmented. It has to do with the JAR file where all the classes are in the default package, which makes Java unable to import them. I solved it by moving my "lib" folder to "src" directory, and the "Grafikk.java" class to "src" as well. Then adding the path to the JAR file in IntelliJ as you normally would, in Project Structure > Libraries. Read more about it here (quote CrazyCoder): How to access java-classes in the default-package?

Datanerd
  • 21
  • 5
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 24 '23 at 15:57