Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Funny NullPointerException

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Location
    Sweden
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Funny NullPointerException

    Hi,

    Sorry for my bad english - I'm a Swede.

    I've written a pretty large Java Applet that runs fine with the appletviewer and in any browser if I run it from disc. But when I've uploaded it to my webpage it produces a NullPointerException. I've scaled down the program to a silly minimum in order to find out what's going wrong. Now, the code looks like this:

    import java.applet.*;
    import java.awt.Graphics;
     
    public class JavaTest extends java.applet.Applet {
     
        public class Dummy {
            public Dummy() {}
        }
        public Dummy ReturnNull() {
            return null;
        }
        public void init() {}
        public void paint(Graphics g) {}
        public void start() {}
        public void stop() {}
        public void run() {}
    }
    Don't mind the run, the original version of the applet uses a thread. However the program above generates a NullPointerException if I run it on my web page. But if I remove the function named ReturnDummy, it runs fine.

    Does anyone have an idea of why I can't have a function that returns an instance of an inner class?

    Best regards
    Marcus
    Last edited by JavaPF; December 5th, 2009 at 09:31 AM. Reason: Please use the [code] [/code] tags.


  2. #2
    Junior Member
    Join Date
    Dec 2009
    Location
    Sweden
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Funny NullPointerException

    Just so that you don't think I'm a complete muppet ...

    The actual applet (not the dummy-version I just posted to show what goes wrong) is produced by my own little programming language (see link: NaaLaa). I'm trying to make it generate java applets instead of windows programs, so that not-so-good-programmers should be able to make games for the web. And it works very well as long as I run the applets from disc via the appletviewer, internet explorer or firefox. But when I put an applet on the web, the mere existance of a function that returns an instance of an inner class causes the nullpointerexception to be generated.

    /Marcus
    Last edited by Marcus; December 5th, 2009 at 09:31 AM.

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Funny NullPointerException

    Whats the full stack trace saying?

    // Json

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Location
    Sweden
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Funny NullPointerException

    Hi,

    The full stack trace says:

    java.lang.NullPointerException
    at sun.plugin2.applet.Plugin2Manager.findAppletJDKLev el(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Undantag: java.lang.NullPointerException

    And it goes away when I remove that method I mentioned.

  5. #5
    Junior Member
    Join Date
    Dec 2009
    Location
    Sweden
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Funny NullPointerException

    Well, I found some more:

    network: Cachepost not found [webbadress: http://www.naalaa.com/javatest$Dummy.class, version: null]
    network: Connecting http://www.naalaa.com/javatest$Dummy.class with proxy DIRECT
    network: Connecting NaaLaa with proxy DIRECT
    basic: exception: null.
    java.lang.NullPointerException
    at sun.plugin2.applet.Plugin2Manager.findAppletJDKLev el(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

    I am a complete beginner when it comes to java, so I don't know exactly what this is about or what I'm talking about. But if I interpret this right, he's looking for a .class-file for the inner class. I assumed he baked them into one file - javatest.class. I guess that explains it all. Sorry for not thinking.
    Last edited by Marcus; December 6th, 2009 at 10:16 AM.

Similar Threads

  1. NullPointerException:null problem
    By derky in forum Exceptions
    Replies: 8
    Last Post: September 18th, 2009, 03:06 PM
  2. [SOLVED] NullPointerException.CLARIFICATION
    By chronoz13 in forum Exceptions
    Replies: 8
    Last Post: August 28th, 2009, 03:24 PM
  3. [SOLVED] NullPointerException in Poker's program
    By dean_martin in forum Exceptions
    Replies: 10
    Last Post: April 21st, 2009, 06:40 AM
  4. Replies: 3
    Last Post: February 26th, 2009, 03:04 AM
  5. NullPointerException in Java
    By jazz2k8 in forum Exceptions
    Replies: 9
    Last Post: June 1st, 2008, 05:59 PM