Applets run in an AppletContext whether provided by the appletviewer or a browser page. If you run an applet from a main method or load the applet into an application there will be no AppletContext and
getCodeBase will return null. In this case you can use an alternate/other image loading method. See
how to import a picture into an applet for some options.