这个问题我还是第一次碰到,首先声明的是,我的编译基本和运行的jre都是1.6的.eclipse也进行Project->clean.
google上很多都说是jre的问题,说指向run configuration中的 classpath 中的 user entities,advance,add folders,然后指向bin目录.
是么,但是都不行.
我甚至删除eclipse的 .metadata然后重新导入项目,还有替换项目下的 .classpath,都不行.
我在同一个包下运行普通的类很正常,但是运行一个继承ImageIcon,实现Runnable的类后,就是这样.
会不会是 swing的问题?我的代码如下:
package spt.proxy;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class ImageIconProxy extends ImageIcon implements Runnable {
public static Object obj = ImageIconProxy.class.getClassLoader().getResource("img/absent.png");
public static final ImageIcon ABSENT = new ImageIcon(
ImageIconProxy.class.getClassLoader().getResource("img/absent.png"));
static final ImageIcon LOADING = new ImageIcon(
ClassLoader.getSystemResource("image/loading.png"));
ImageIcon current = ABSENT;
protected String fileName = null;
protected JFrame callbackFrame = null;
public ImageIconProxy(String fileName) {
// super(ABSENT.getImage());
System.out.println("absent:" + ABSENT);
this.fileName = fileName;
}
public void load(JFrame callbackFrame) {
this.callbackFrame = callbackFrame;
current = LOADING;
callbackFrame.repaint();
new Thread(this).start();
}
@Override
public void run() {
current = new ImageIcon(ClassLoader.getSystemResource(fileName));
callbackFrame.pack();
}
public int getIconWidth() {
return current.getIconWidth();
}
public int getIconHeight() {
return current.getIconHeight();
}
public void show() {
callbackFrame.setVisible(true);
}
public static void main(String[] args) {
System.out.println("absent:" );
}
}
------解决思路----------------------
public static Object obj = ImageIconProxy.class.getClassLoader().getResource("img/absent.png");这几个静态属性初始化有问题,导致你这个类加载失败,所以提示找不到main class,跟swing没关系
public static final ImageIcon ABSENT = new ImageIcon(
ImageIconProxy.class.getClassLoader().getResource("img/absent.png"));
static final ImageIcon LOADING = new ImageIcon(
ClassLoader.getSystemResource("image/loading.png"));