我整个班级的代码是:

package picturetest;
import images.APImage;

public class PictureTest{

    public static void main(String[]args){
        APImage image = new APImage("cat4.jpg"); //Line 12
        image.draw();

    }
}


运行此命令时,出现以下错误:

javax.imageio.IIOException: Can't read input file!
Exception in thread "main" java.lang.NullPointerException
    at images.APImage.setWindowAttributes(APImage.java:230)
    at images.APImage.<init>(APImage.java:86)
    at picturetest.PictureTest.main(PictureTest.java:12)
Java Result: 1

最佳答案

您可以使用以下代码打印工作目录:

System.out.println(System.getProperty("user.dir"));


给出与此相关的“ cat4.jpg”路径。

10-04 11:08