From 95a58a87579950c08230d3713e7d0251774821a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Kvarnstr=C3=B6m?= Date: Sat, 16 Jan 2021 14:47:59 +0100 Subject: Added comment to resource reader --- src/se/liu/tddd78/examples/ResourceTester.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/se/liu/tddd78/examples/ResourceTester.java b/src/se/liu/tddd78/examples/ResourceTester.java index d18a3e6..9898293 100644 --- a/src/se/liu/tddd78/examples/ResourceTester.java +++ b/src/se/liu/tddd78/examples/ResourceTester.java @@ -52,6 +52,12 @@ public class ResourceTester // Like above, we need to access the image through a resource. final URL image = ClassLoader.getSystemResource("images/hello_world.png"); + // If the image does not exist, image will be null, and a NullPointerException + // will be thrown when the ImageIcon is created below. This is OK in this + // very specific case, because each *resource* is an integral part of the + // program. It cannot be missing unless the project is damaged, + // in which case all bets are off in any case. + // The ImageIcon class can read an entire image directly from any URL. ImageIcon icon = new ImageIcon(image); -- cgit v1.2.1