我是java的初学者,我刚刚开始使用applet和applet&东西都有效...但每次我尝试运行它我都会收到这个错误:
--------------------Configuration: AlexVega - JDK version 1.8.0_20 <Default> - <Default>--------------------
load: class Game.class not found.
java.lang.ClassNotFoundException: Game.class
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:219)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:152)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:634)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:799)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:728)
at sun.applet.AppletPanel.run(AppletPanel.java:378)
at java.lang.Thread.run(Thread.java:745)
Process completed.
这是我的计划:
package com.alexvega;
import java.applet.*;
import java.awt.*;
public class Game extends Applet{
private boolean running = false;
private Thread thread;
public synchronized void start(){
if(running)
return;
running = true;
thread = new Thread(thread);
thread.start();
}
public void run(){
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int updates = 0;
int frames = 0;
while(running){
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while(delta >= 1){
int tick;
updates++;
delta--;
}
int render;
frames++;
if(System.currentTimeMillis() - timer > 1000){
timer += 1000;
System.out.println("FPS: " + frames + " TICKS: " + updates);
frames = 0;
updates = 0;
}
}
}
public static void main(String args[]){
}
public void paint(Graphics g){
setBackground(Color.BLACK);
}
}
这是该计划的第二部分:
package com.alexvega;
public class Window {
public Window(Game game){
game.start();
}
}
我做错了什么???
答案 0 :(得分:0)
您的代码没有任何问题。它只是意味着在运行时无法找到/加载Java类,这对Java开发人员来说是一个非常常见的问题。从错误中,它说class Game.class not found
是自我解释的。
您需要设置类路径以告诉编译器您的类在哪里。
查看this link以获取有关如何设置类路径的说明(适用于您的Game类)。此外,还有更多网站提供相关说明。
快乐的编码。