0
イメージをロードするだけです。IntelliJ javax.imageio.IIOException:入力ファイルを読み取ることができません
古いプログラムでは動作します。唯一の違いは、古いものはディレクトリを使用し、これはパッケージを使用することです。実際にはディレクトリを作成することすらできません。スタックトレースザッツ
:
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
at com.company.ImageLoader.loadImage(ImageLoader.java:17)
at com.company.Window.Window.<init>(Window.java:30)
at com.company.Engine.<init>(Engine.java:21)
at com.company.Main.main(Main.java:8)
public class Window
{
private JFrame myFrame;
private JPanel mainPanel;
private JLabel mainLabel;
private ImageLoader myImageLoader = new ImageLoader();
public Window(Boolean defaultLaFDeco, String title, int x, int y, int width, int height)
{
JFrame.setDefaultLookAndFeelDecorated(defaultLaFDeco);
myFrame = new JFrame();
myFrame.setTitle(title);
mainPanel = new JPanel();
mainLabel = new JLabel();
mainPanel.add(mainLabel);
myFrame.add(mainPanel);
myFrame.setBounds(x,y,width,height);
myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
myFrame.setVisible(true);
File file = new File("Res/cat/0.jpg");
BufferedImage img = myImageLoader.loadImage(file);
}
}
public class ImageLoader
{
private BufferedImage image = null;
public BufferedImage loadImage(File file)
{
BufferedImage img = null;
try
{
img = ImageIO.read(file);
} catch (IOException e)
{
e.printStackTrace();
}
return img;
}
}
パッケージツリーにディレクトリを作成することはできません。 ''新しいファイル( "../Res/cat/0.jpg"); '' –