H
Hamas
Gast
Hallo Community!
Kann mir wer helfen beim Finden des Fehlers?
Liegt es vielleicht an den Pfad? Ich habe das Bild im workspace im Projektordner (nur zum Test).
Ich hab einen anderer Pfad auch versucht: "Bibliotheken/Bilder/diablo.jpg" doch hier sagt er auch = NULL?!?!
Bitte um Hilfe...
Fehlercode:
mit freundlichen Grüßen
Hamas
Kann mir wer helfen beim Finden des Fehlers?
Liegt es vielleicht an den Pfad? Ich habe das Bild im workspace im Projektordner (nur zum Test).
Ich hab einen anderer Pfad auch versucht: "Bibliotheken/Bilder/diablo.jpg" doch hier sagt er auch = NULL?!?!
Bitte um Hilfe...
Java:
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class FrameDecoration
{
public static void main(String[] args)
{
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new BackgroundPanel());
f.setSize(400,300);
f.setLocation(200,200);
f.setVisible(true);
}
}
class BackgroundPanel extends JPanel
{
Image image;
public BackgroundPanel()
{
loadImage();
setBackground(Color.yellow);
this.setOpaque(false);
}
public void paintComponent(Graphics g)
{
int width = getWidth();
int height = getHeight();
int imageWidth = image.getWidth(this);
int imageHeight = image.getHeight(this);
int x = (width - imageWidth)/2;
int y = (height - imageHeight)/2;
g.drawImage(image, x, y, this);
super.paintComponent(g);
}
private void loadImage()
{
String fileName = ("test.jpg");
try
{
URL url = getClass().getResource(fileName);
image = ImageIO.read(url);
}
catch(MalformedURLException mue)
{
System.out.println(mue.getMessage());
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}
}
Fehlercode:
Java:
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at BackgroundPanel.loadImage(FrameDecoration.java:49)
at BackgroundPanel.<init>(FrameDecoration.java:26)
at FrameDecoration.main(FrameDecoration.java:13)
mit freundlichen Grüßen
Hamas