import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.io.*;
public class one extends JFrame {
public one()
{
JPanel p = new JPanel();
JLabel l = new JLabel();
setTitle("ScrollText");
setSize(600, 400);
setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
BufferedImage image;
p.add(l);
add(p);
try
{
File file = new File("D://Photos//foto(222).jpg");
image = ImageIO.read(file);
l.setIcon(new ImageIcon(image));
}
catch( Exception e)
{
System.out.println(e.getMessage());
l.setText("Cannot read image");
}
}
public static void main(String[] args)
{
new one();
}
}
This is my code..
when i run this code error appear..
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(Unknown Source)
at one.<init>(one.java:26)
at one.main(one.java:40)
Can't read input file!
Please give solution...
sush jack
0
Newbie Poster
Recommended Answers
Jump to PostMake sure the path to the file is correct.
Jump to PostRather than just printing the exception's messgae, do a full e.printStackTrace();
This will give you the details of any errors that caused the exception eg file not found, incorrect priveleges to read file etc etc
All 7 Replies
NormR1
563
Posting Sage
Team Colleague
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NormR1
563
Posting Sage
Team Colleague
sush jack
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
sush jack
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.