Ok, so I'm having a program where you can upload images of a house for rent, and the image is then copied over to a directory where all images are. Then in another window it loads all the images to presentation that I can click on. This is working perfectly fine when compiling and running through Sublime Text. But after creating a .jar file and running it, there's some problems. I can upload an image and copy it over to the image directory fine, but when I go to the other JFrame-window where all the images are supposed to be presented, it locks the program and have to be closed through task manager. Any suggestions?
Here's the code when starting the program, where stock images of some houses are loaded into the main image directory for all images of houses:
public void copyStockImages(String filename)
{
String filepath = "Images/Testimages/" + filename;
BufferedImage image = null;
try {
image = ImageIO.read(getClass().getResource(filepath));
}
catch( FileNotFoundException fnfe ){
System.out.println( "File not found: " + filepath );
}
catch( IOException ioe ){
System.out.println( "Error reading image" );
}
String newFilePath = "Images/houseImages/" + filename;
File fileOut = new File( newFilePath );
if( fileOut.exists() ){
return;
}
try{
ImageIO.write( image, "jpg", fileOut );
}
catch( IOException ioe ){
System.out.println( "Error reading image" );
}
}
Upload images:
private void uploadImages(HouseForRent house) {
if(filepaths.isEmpty()) {
return;
}
Iterator<String> iter = filepaths.iterator();
while( iter.hasNext() ) {
String filepath = i.next();
String filetype = findFiletype( filepath );
BufferedImage image = null;
try {
image = ImageIO.read( new File( filepath ) );
}
catch( FileNotFoundException fnfe ) {
dialog( "Cannon find file: " + filepath );
}
catch( IOException ioe ) {
dialog( "Error reading file" );
}
catch(NullPointerException npe) {
}
try {
saveImage( image, filetype, house );
}
catch( IOException ioe ) {
dialog( "Error reading from file: " + ioe.toString() );
}
catch( NullPointerException npe ) {
dialog( "Error: " + npe.toString() );
}
}
}
Copying the image over to a directory:
private void saveImage( BufferedImage image, String filetype, HouseForRent house ) throws IOException{
String newFilePath = "Images/houseImages/";
String filelink = newFilepath + filetype;
File fileOut = new File( filelink );
if( fileOut.exists() ) {
house.addImage(filelink);
return;
}
try {
ImageIO.write( image, "jpg", fileOut );
}
catch( Exception e ) {
dialog( "Error reading image" );
}
house.addImage(filelink);
imageLinks.add( filelink );
}
Then I have this long Image class which I posted the code at PasteBin:
http://pastebin.com/yjzZdVTC