Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Java getImage()


ghost's Avatar
0 0

Ok using getImage with a URL in Java I keep getting the following error:

markupunreported exception java.net.MalformedURLException; must be caught or declated to be thrown

the line is: markupImage img1 = getImage(new URL("http://www.google.co.uk/intl/en_uk/images/logo.gif"));

Any help?


ghost's Avatar
0 0

Ok I did what spyware's link showed and it doesn't give me an error anymore, it just doesn't load an image at all

	
		try{
			LoadMyImage("http://www.google.co.uk/intl/en_uk/images/logo.gif");
		} catch (MalformedURLException e){
			// Do nothing
		}
		
	}
	
	public void LoadMyImage(String ur) throws MalformedURLException {
		u = new URL(ur);
		Image img1 = getImage(u);
		repaint();
	}```

There's my code, does anyone see any errors?

spyware's Avatar
Banned
0 0

Follow the advice Zephyr posted, it explains pretty much everything from scratch.


ghost's Avatar
0 0

The page he linked to is the one I was already using to start with ^^


ynori7's Avatar
Future Emperor of Earth
0 0

x_5631 wrote: Ok I did what spyware's link showed and it doesn't give me an error anymore, it just doesn't load an image at all

	
		try{
			LoadMyImage("http://www.google.co.uk/intl/en_uk/images/logo.gif");
		} catch (MalformedURLException e){
			// Do nothing
		}
		
	}
	
	public void LoadMyImage(String ur) throws MalformedURLException {
		u = new URL(ur);
		Image img1 = getImage(u);
		repaint();
	}```

There's my code, does anyone see any errors?

it's not that it isnt giving an error anymore, it is just catching the error and then it does nothing. this code doesnt solve the problem, it just handles the situation differently if the problem arises.

try{
LoadMyImage("http://www.google.co.uk/intl/en_uk/images/logo.gif");
} catch (MalformedURLException e){
//if you were to put something in here it wouldnt do nothing
}

ghost's Avatar
0 0

Do you know what I need to do to avoid getting that error then? Rather than just catching it..