Import javax swing jframe ошибка

I’ve been looking all over the internet and Can’t find an answer.

I’m using Eclipse and need to import JFrame from javax.swing. But hovering over the the declaration (which in Eclipse should give you an option to import it) the import option does not show up. Instead I manually typed out the import path, but get an error.

Going even further, I used the package explorer to attempt to fine it… couldn’t. I have the latest version of Eclipse, and the Latest JRE and JDK. But still is not working.

Code:

package com.BickDev.Game;

import java.awt.Canvas;
import java.awt.Dimension;

import javax.swing.JFrame;

public class Game extends Canvas implements Runnable {
    private static final long serialVersionUID = 1L;

    public static final int WIDTH = 320;
    public static final int HEIGHT = WIDTH / 12 * 9;
    public static final int SCALE = 2;
    public final String TITLE = "Troy's Game Test";
    private boolean running = false;


    public void run() {

    }

    public static void main(String args[]) {

        Game game = new Game();
        Dimension size = new Dimension(WIDTH * SCALE, HEIGHT * SCALE);
        game.setPreferredSize(size);
        game.setMaximumSize(size);
        game.setMinimumSize(size);

        JFrame frame = new JFrame(game.TITLE);
    }
}

the import javax.swing.JFrame now gives the error

Access restriction: The type JFrame is not accessible due to restriction on required library C:\ProgramFiles\Java\jre8\lib\rt.jar

No idea what this means…

Please help….

*UPDATE found the JFrame class.. but cannot access it.

I’ve been looking all over the internet and Can’t find an answer.

I’m using Eclipse and need to import JFrame from javax.swing. But hovering over the the declaration (which in Eclipse should give you an option to import it) the import option does not show up. Instead I manually typed out the import path, but get an error.

Going even further, I used the package explorer to attempt to fine it… couldn’t. I have the latest version of Eclipse, and the Latest JRE and JDK. But still is not working.

Code:

package com.BickDev.Game;

import java.awt.Canvas;
import java.awt.Dimension;

import javax.swing.JFrame;

public class Game extends Canvas implements Runnable {
    private static final long serialVersionUID = 1L;

    public static final int WIDTH = 320;
    public static final int HEIGHT = WIDTH / 12 * 9;
    public static final int SCALE = 2;
    public final String TITLE = "Troy's Game Test";
    private boolean running = false;


    public void run() {

    }

    public static void main(String args[]) {

        Game game = new Game();
        Dimension size = new Dimension(WIDTH * SCALE, HEIGHT * SCALE);
        game.setPreferredSize(size);
        game.setMaximumSize(size);
        game.setMinimumSize(size);

        JFrame frame = new JFrame(game.TITLE);
    }
}

the import javax.swing.JFrame now gives the error

Access restriction: The type JFrame is not accessible due to restriction on required library C:\ProgramFiles\Java\jre8\lib\rt.jar

No idea what this means…

Please help….

*UPDATE found the JFrame class.. but cannot access it.

Я смотрю по всему Интернету и не могу найти ответ.

Я использую Eclipse и мне нужно импортировать JFrame из javax.swing. Но зависание над объявлением (которое в Eclipse должно предоставить вам возможность импортировать его) параметр импорта не отображается. Вместо этого я вручную напечатал путь импорта, но получаю сообщение об ошибке.

Идя еще дальше, я использовал проводник пакетов, чтобы попытаться это сделать… не смог. У меня есть последняя версия Eclipse, а также последняя JRE и JDK. Но все еще не работает.

код:

package com.BickDev.Game;

import java.awt.Canvas;
import java.awt.Dimension;

import javax.swing.JFrame;

public class Game extends Canvas implements Runnable {
    private static final long serialVersionUID = 1L;

    public static final int WIDTH = 320;
    public static final int HEIGHT = WIDTH / 12 * 9;
    public static final int SCALE = 2;
    public final String TITLE = "Troy Game Test";
    private boolean running = false;


    public void run() {

    }

    public static void main(String args[]) {

        Game game = new Game();
        Dimension size = new Dimension(WIDTH * SCALE, HEIGHT * SCALE);
        game.setPreferredSize(size);
        game.setMaximumSize(size);
        game.setMinimumSize(size);

        JFrame frame = new JFrame(game.TITLE);
    }
}

импорт javax.swing.JFrame теперь дает ошибку

Access restriction: The type JFrame is not accessible due to restriction on required library C:\ProgramFiles\Java\jre8\lib\rt.jar

Не знаю, что это значит…

Пожалуйста, помогите….

* UPDATE нашел класс JFrame.. но не может получить к нему доступ.

Solution 1

When you make a new java project at JRE choose «Use an execution environment JRE and from there select JavaSE-1.7 or 1.8 and just should solve the problem. I had the same problem like you before.

Solution 2

Just add requires java.desktop; to your module-info.java file.

module-info.java:

module your_project_name{
    requires java.desktop;
}

Solution 3

  1. Right-click on the project
  2. Select properties
  3. Java build path
  4. Library > Add Library > Add JRE SYSTEM Library
  5. Execution Environment
  6. Select JavaSE-1.7
  7. Finish

Related videos on Youtube

Java GUI Tutorial - Make a GUI in 13 Minutes

12 : 58

Java GUI Tutorial — Make a GUI in 13 Minutes

Java Tutorial for Beginners using Eclipse: javax swing cannot resolved error | solution

08 : 11

Java Tutorial for Beginners using Eclipse: javax swing cannot resolved error | solution

Connect your java project in netbeans with xampp

08 : 18

Connect your java project in netbeans with xampp

javax.swing Cannot Be Resolved Error Fix

01 : 11

javax.swing Cannot Be Resolved Error Fix

Fix JavaFX Import Error in Eclipse

05 : 43

Fix JavaFX Import Error in Eclipse

Java open a new GUI window 🗔

10 : 53

Java open a new GUI window 🗔

How to fix Eclipse import error (JavaFX using JDK8)

02 : 46

How to fix Eclipse import error (JavaFX using JDK8)

Java GUI Setup in Eclipse

06 : 22

Java GUI Setup in Eclipse

Java project not showing Output and BUILD SUCCESSFUL (total time: 6 seconds) In NetBeans 12.3

01 : 55

Java project not showing Output and BUILD SUCCESSFUL (total time: 6 seconds) In NetBeans 12.3

Why Windowbuilder not working in Eclipse || What to do Windowbuilder Eclipse not show Design tab??

06 : 44

Why Windowbuilder not working in Eclipse || What to do Windowbuilder Eclipse not show Design tab??

Java Tutorial for Beginners

02 : 30 : 48

Java Tutorial for Beginners

How to remove unknown GUI Toolkit error in Eclipse IDE .Unknown GUI Toolkit error कैसे  दूर करे

04 : 02

How to remove unknown GUI Toolkit error in Eclipse IDE .Unknown GUI Toolkit error कैसे दूर करे

Java Swing.Swing Introduction.First Swing Example.#import.javax.swing.*;#JavaBasics.

05 : 16

Java Swing.Swing Introduction.First Swing Example.#import.javax.swing.*;#JavaBasics.

Everything for the designer

How to fix package javax.swing is not accessible

01 : 57

How to fix package javax.swing is not accessible

Comments

  • I’ve been looking all over the internet and Can’t find an answer.

    I’m using Eclipse and need to import JFrame from javax.swing. But hovering over the the declaration (which in Eclipse should give you an option to import it) the import option does not show up. Instead I manually typed out the import path, but get an error.

    Going even further, I used the package explorer to attempt to fine it… couldn’t. I have the latest version of Eclipse, and the Latest JRE and JDK. But still is not working.

    Code:

    package com.BickDev.Game;
    
    import java.awt.Canvas;
    import java.awt.Dimension;
    
    import javax.swing.JFrame;
    
    public class Game extends Canvas implements Runnable {
        private static final long serialVersionUID = 1L;
    
        public static final int WIDTH = 320;
        public static final int HEIGHT = WIDTH / 12 * 9;
        public static final int SCALE = 2;
        public final String TITLE = "Troy's Game Test";
        private boolean running = false;
    
    
        public void run() {
    
        }
    
        public static void main(String args[]) {
    
            Game game = new Game();
            Dimension size = new Dimension(WIDTH * SCALE, HEIGHT * SCALE);
            game.setPreferredSize(size);
            game.setMaximumSize(size);
            game.setMinimumSize(size);
    
            JFrame frame = new JFrame(game.TITLE);
        }
    }
    

    the import javax.swing.JFrame now gives the error

    Access restriction: The type JFrame is not accessible due to restriction on required library C:\ProgramFiles\Java\jre8\lib\rt.jar
    

    No idea what this means…

    Please help….

    *UPDATE found the JFrame class.. but cannot access it.

    • Thanks madProgrammer. this solved it

  • You are welcom, you can contact me any time @austin-mullins

Recents

Related

Issue

I’ve been looking all over the internet and Can’t find an answer.

I’m using Eclipse and need to import JFrame from javax.swing. But hovering over the the declaration (which in Eclipse should give you an option to import it) the import option does not show up. Instead I manually typed out the import path, but get an error.

Going even further, I used the package explorer to attempt to fine it… couldn’t. I have the latest version of Eclipse, and the Latest JRE and JDK. But still is not working.

Code:

package com.BickDev.Game;

import java.awt.Canvas;
import java.awt.Dimension;

import javax.swing.JFrame;

public class Game extends Canvas implements Runnable {
    private static final long serialVersionUID = 1L;

    public static final int WIDTH = 320;
    public static final int HEIGHT = WIDTH / 12 * 9;
    public static final int SCALE = 2;
    public final String TITLE = "Troy's Game Test";
    private boolean running = false;


    public void run() {

    }

    public static void main(String args[]) {

        Game game = new Game();
        Dimension size = new Dimension(WIDTH * SCALE, HEIGHT * SCALE);
        game.setPreferredSize(size);
        game.setMaximumSize(size);
        game.setMinimumSize(size);

        JFrame frame = new JFrame(game.TITLE);
    }
}

the import javax.swing.JFrame now gives the error

Access restriction: The type JFrame is not accessible due to restriction on required library C:\ProgramFiles\Java\jre8\lib\rt.jar

No idea what this means…

Please help….

*UPDATE found the JFrame class.. but cannot access it.

Solution

When you make a new java project at JRE choose «Use an execution environment JRE and from there select JavaSE-1.7 or 1.8 and just should solve the problem. I had the same problem like you before.

Answered By — user3623053
Answer Checked By — Clifford M. (JavaFixing Volunteer)

Понравилась статья? Поделить с друзьями:
  • Ilife a40 ошибки
  • Import cv2 python ошибка
  • Immergas ошибка 11 как исправить ошибку
  • Import android support v7 app appcompatactivity ошибка
  • Idmss plus ошибка подключения