0

Hi

I encountered a strange problem today when i tried to run my java program from a batch file.
I have a fullscreen mode java application and i tried to run the application from a batch file .Now the problem is images are not being loaded when i run my program using batch file.
I executed manually from the command prompt and was shocked to see that even now the problem is not fixed.
I generally use my favourate Editplus editor. When i execute from my editor,
there is no such problem and everything works fine.

I rec-checked the path of images twice and there's no problem with that.

I really dont know what's stopping the images from being loaded when i execute from batch file.

Edited by harinath_2007: n/a

4
Contributors
15
Replies
16
Views
5 Years
Discussion Span
Last Post by NormR1
0

Are there any error messages when you manually execute the program?
Does your code ignore exceptions or does it use printStackTrace when it catches an exception?

0
JLabel img=new JLabel(new ImageIcon("d:/myproject/image1.jpg"));

I also tried without abolute path as the image files and program is in same directory.

0

What is different about when the code works and when it fails?
Does it ever work when you use an absolute path like your last post?

0

new ImageIcon is a pain because it fails without giving any diagnostics - where it should throw an exception it just returns null.
If you temporarily replace that with trying to read the file into a vanilla Image object then you should get an exception that explains exactly what's going wrong.

0

Or you should change your code to read the icon into its own variable and test that variable for null and print out a message if its null.

0

make sure your image is exactly like in windows. instead of

JLabel img=new JLabel(new ImageIcon("d:/myproject/image1.jpg"));

try this

JLabel img=new JLabel(new ImageIcon("D:\\myproject\\image1.jpg"));
0

The code works even when i use absolute path.

Whether i use absolute path or entire path , the images are being loaded when i execute my program from my editor.

When i execute the same from a batch file or from command prompt , the images are not being loaded.

0

The entire screen turns white color and images are not being displayed on the screen .
But the Jprogressbar and some text labels are being displayed.

0

Is there any other way to load the images ?

File imageFile = new File(path);
if (!imageFile.exists()) // display error message
Image image = ImageIO.read(imageFile); // throws IOException
ImageIcon io = new ImageIcon(image);

This does the same thing with more code, but has the advantage of throwing exceptions and issuing error messages that help diagnose any problems

Edited by JamesCherrill: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.