Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default I am created this program.but it shows null pointer exception...can any one help me..

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Progress extends JFrame implements Runnable,ActionListener
    {
    JProgressBar jp=new JProgressBar(1,100);
    Container con=getContentPane();
    Button b1=new Button("start");
    Thread t;
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==b1)
    {
    new Thread(this);
    t.start();
    }
    }
    public void run()
    {
    try
    {
    for(int i=1;i<101;i++)
    {
    jp.setValue(i);
    t.sleep(10);
    }
    }
    catch (Exception ex)
    {
    System.out.println("ERROR HAS OCCURED.....SORRY.....");
    }
    }
    public static void main(String args[])
    {
    new Progress();
    }
    public Progress()
    {
    con.setLayout(new FlowLayout());
    con.add(jp);
    con.add(b1);
    b1.addActionListener(this);
    setSize(300,100);
    setVisible(true);
    setTitle("PROGRESSBAR");
    }
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    All you've done is dump your code(without code tags), why not provide us with useful information? What is the exact error message you see(copy/paste it)?

    To use code tags do the following
    [code]
    YOUR CODE HERE
    [/code]

    That being said; without looking at your code I can say pretty confidently that you haven't initialized something and you tried calling a method on it. Try adding print statements to print different variables throughout the program. Also, follow the stack trace the exception gives you back to the line which caused the exception.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default

    Would you like to reply to Fubarable's response on the thread you started yesterday? Like maybe to say 'Thank you'?

    Or is it your intention to start thread after thread and never get back to them?

    db

  4. #4
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    i found the error.....in if loop have to add t. so the line like this now t=new Thread(this);

Similar Threads

  1. Replies: 6
    Last Post: 06-27-2011, 08:40 AM
  2. Replies: 4
    Last Post: 06-11-2011, 01:35 AM
  3. Null Pointer Exception
    By jonytek in forum New To Java
    Replies: 5
    Last Post: 03-02-2011, 07:16 AM
  4. Null pointer exception
    By samuel.roshni in forum Java Servlet
    Replies: 14
    Last Post: 01-22-2011, 02:25 PM
  5. Null Pointer exception
    By diegoyj in forum New To Java
    Replies: 7
    Last Post: 01-29-2010, 04:17 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
  •