Javaを使用してゲームを作成し始めたばかりです。問題は、このエラーのために実行されないことです:
Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.maze.game
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Java 例外が発生したと表示されますが、他のすべてのプログラムは実行されます。私はもう試した:
- Java のアンインストールと再インストール
- 最新の Eclipse プログラムを実行する (私は Juno を実行しています)
これが私のコードです:
package java.maze.game;
import java.awt.BorderLayout;
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 = 160;
public static final int HEIGHT = WIDTH/12*9;
public static final int SCALE = 3;
public static final String NAME = "Maze game";
public boolean running = false;
private JFrame frame;
public Game(){
setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE)); //sets the minimum size of the frame
setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE)); //sets the maximum size of the frame
setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE)); //sets the preferred size of the frame
frame = new JFrame(NAME); //creates the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //set the default for what happens when the program is exited
frame.setLayout(new BorderLayout()); //creating a new layout for the frame
frame.add(this, BorderLayout.CENTER); //keeps everything centered not overlapping the taskbar
frame.pack(); //sets the frame above or at the preferred size
frame.setResizable(false); //makes sure the user can't resize the frame
frame.setLocationRelativeTo(null); //we don't want the location of the screen relative to any variable
frame.setVisible(true); //sets the frame to visible
}
public void start() {
running = true;
new Thread(this).start(); //whenever the Thread is started it will run the run(); method
}
public void stop() {
running = false;
}
public void run() {
while(running){
System.out.println("It worked!");
}
}
public static void main(String[] args){
new Game().start();
}
}
ありがとうございました!
EDIT 今はばかのように感じますが、もう一度ありがとう.