Results 1 to 2 of 2
  1. #1
    barney is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default ERROR: nullPointerException in applet

    Hi, I have this applet that starts as soon as the page is loaded. But i wanted it so you have to click the applet before it starts(getting keyboard focus) or else its just a race to click the applet before you die... so i tried the following:
    Java Code:
    public class Whatever implements Runnable,KeyListener,MouseListener{
    ...
    Graphics begin;
    Thread th;
    ...
    public void init(){
     ...
     begin.drawString("click to start",100,50);
     addMouseListener(this);
    }
    ...
    public void mousePressed(MouseEvent e){
     begin.dispose();
     th.start();
    }
    And i got a NullPointerException... whatever that is. So everything else works fine.
    Could anyone tell me a better way to go about this or a way to fix it?
    Thanks.

  2. #2
    lenny is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    NullPointerException means that you're trying to use an object that is null, i.e., you haven't "new"-ed it.
    You're not showing all of the code, and you didn't say when exactly you're getting the exception (immediately, or when you click the applet with the mouse?). Are you sure you created th, because I don't see that in the code, and if you didn't then th.start() would throw an NullPointerException because that is null.

Similar Threads

  1. NullPointerException
    By ravian in forum New To Java
    Replies: 2
    Last Post: 12-07-2007, 05:20 PM
  2. NullPointerException
    By Feng in forum New To Java
    Replies: 5
    Last Post: 11-24-2007, 08:51 PM
  3. ERROR: nullPointerException
    By mathias in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 07:54 AM
  4. applet error
    By Peter in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 08:04 AM
  5. Replies: 2
    Last Post: 07-02-2007, 03:29 AM

Posting Permissions

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