getClass(). getResource() returns null

Asked

Viewed 104 times

1

The following code normally functions:

package com.lucasdaniel;

package com.lucasdaniel;
import java.net.URL;

public class Main {

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

    static class Subclass {
        public Subclass() {
            URL resource = getClass().getResource("css.css");
            System.out.println(resource);
        }
    }
}

But when I create module-info.java, Resource gets null.

build.Radle looks like this:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

group 'com.lucasdaniel'
version '1.0-SNAPSHOT'

mainClassName = "untitled/com.lucasdaniel.Main"

repositories {
    mavenCentral()
}

javafx {
    version '11.0.2'
    modules = ['javafx.fxml', 'javafx.controls']
}

the project files are like this:

os arquivos do projeto estão assim

  • You’re running it inside a JAR?

  • I’m not running into jar

1 answer

0

Use getResource for the class

URL resource = Subclass.class.getClassLoader().getResource("css.css");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.