Results 1 to 2 of 2
  1. #1
    fernando is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default Help with method getCodeBase()

    Hi, I'm trying to load an Image for my applet:

    Java Code:
    getImage(getCodeBase(), "ship.gif")
    It compiles fine, but when I try to run it getCodeBase() returns a nullPointerException.

    This is really confusing as I cant find another way to do this...


  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    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.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 06:12 PM
  2. Method Help
    By pringle in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 02:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts