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.

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?

I have used printStackTrace and there are no error messages in my code.

What code are you using to load the images? What exactly does your image file path look like?

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.

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?

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.

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.

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"));

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.

What do the calls to new ImageIcon() return? Are they null or ??

The ImageIcon is not null .

Is there any other way to load the images ?

If it's not null then the image IS being loaded. What exactly is the symptom you described in your first post?

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.

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

The OP has to post a SSCCE that shows the problem.
We're arguing about ghosts.

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.