Brandon
Brandon

Reputation: 23510

Get IntelliJ to recognize modified internal class method

In NetBeans I created a class: java.awt.Canvas (I use -XBootClassPath). In this class, I add a function call: "addPaintListener".

When I compile, it works fine. I can write code like (In netbeans. No errors):

public static void notifyCanvasReady(Canvas canvas) {
    canvas.addPaintListener((PaintListener) g -> {
        g.setColor(Color.white);
        g.drawString("HELLO WORLD", 50, 50);
    });
}

But in IntelliJ, it gives me an error:

enter image description here


However, if I Right-Click the project and hit compile module, it compiles fine (still shows the error) but actually runs regardless.

enter image description here


Any idea how I can get it to stop showing the error or get it to recognize my modified internal class?

Upvotes: 0

Views: 164

Answers (1)

Bas Leijdekkers
Bas Leijdekkers

Reputation: 26482

The comments are right that you are not supposed to modify JDK classes, if you are not a JDK engineer. However let's assume you really want to do this. The following should work:

  • Go to the project settings File | Project Structure...
  • Click on Modules in the left panel
  • Select your module in the middle panel (the one called BotTutorial I assume)
  • Go to the Dependencies tab in the right panel
  • Move <Module source> up above the JDK in the table using drag&drop or the arrow buttons at the bottom.

Here's what the dialog looks like. <Module source> should be at the top of the table, above the 1.7_15 JDK. Project Structure Module Dependencies

Upvotes: 1

Related Questions