Old 11-26-2006, 10:27 AM   #1 (permalink)
500+ Posts????
 
Shattered Skies's Avatar
 
Join Date: May 2006
Location: Indiana, USA
Posts: 512
Reputation: 19
Send a message via ICQ to Shattered Skies Send a message via AIM to Shattered Skies Send a message via MSN to Shattered Skies Send a message via Yahoo to Shattered Skies
Default Java Issue

Okay, Ive been up for way too long and don't feel like staring more at this code trying to figure out why its not compiling correctly for me. So, anyone care to see why Im getting these errors:

Code:
init:
deps-jar:
compile-single:
run-single:
Exception in thread "main" java.lang.NullPointerException
        at JNotePad.MenuBar.createFileMenu(MenuBar.java:84)
        at JNotePad.MenuBar.<init>(MenuBar.java:15)
        at JNotePad.MenuBar.main(MenuBar.java:104)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
With this code:

Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MenuBar extends JFrame
{
    private JMenuBar menubar;
    
    public MenuBar()
    {
        setTitle("Test");

        createFileMenu();
     //   createEditMenu();
     //   createHelpMenu();
        
        setJMenuBar(menubar);
        
        setSize(400,400);
        setVisible(true);
    }
    
    private void createFileMenu()
    {
        JMenu menu = new JMenu("File");     // Create File menu.
        menu.setMnemonic(KeyEvent.VK_F);    // Underlined F
        
        JMenuItem menuItem = new JMenuItem("Save", null);
        menuItem.setMnemonic(KeyEvent.VK_S);    // Underline S
        
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
        menuItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                showDialog("Are you sure you want to save?", "Save?",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            }
        });
        menu.add(menuItem);
        
        menuItem = new JMenuItem("Save As...", null);
        menuItem.setMnemonic(KeyEvent.VK_A);
        
        menuItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                showDialog("Are you sure you wish to save all?", "Save All", 
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            }
        });
        menu.add(menuItem);
        menu.addSeparator();
        
        menuItem = new JMenuItem("Delete", null);
        menuItem.setMnemonic(KeyEvent.VK_D);
        
        menuItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                showDialog("Are you sure you want to delete? Information cant be recovered!", "Delete?",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            }
        });
        menu.add(menuItem);
        menu.addSeparator();
        
        menuItem = new JMenuItem("Exit", null);
        menuItem.setMnemonic(KeyEvent.VK_X);
        
        menuItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                showDialog("Are you sure you want to exit?", "Exit",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            }
        });
        menu.add(menuItem);
        menubar.add(menu);
    }
    /*
    private void createEditMenu()
    {
        
    }
    
    private void createHelpMenu()
    {
        
    }
    */
    public void showDialog(String message, String title, int option, int icon)
    {
        JOptionPane.showInternalConfirmDialog(null, message, title, option, icon);
    }
    
    public static void main(String[] args)
    {
        MenuBar mb = new MenuBar();
        mb.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
}
As simple as the program is I cant figure it out. Meh.. sleep sucks.
Shattered Skies is offline  
Old 11-26-2006, 02:38 PM   #2 (permalink)
Cloud's Hair Spray
 
Join Date: Jun 2006
Location: Netherlands
Posts: 61
Reputation: 10
Send a message via MSN to ractoc
Default

Very simple:
You define an instance variable called menuBar. You don't initialise it though. But you DO call a member method on it on line 84.
ractoc is offline  
Old 11-27-2006, 01:24 PM   #3 (permalink)
500+ Posts????
 
Shattered Skies's Avatar
 
Join Date: May 2006
Location: Indiana, USA
Posts: 512
Reputation: 19
Send a message via ICQ to Shattered Skies Send a message via AIM to Shattered Skies Send a message via MSN to Shattered Skies Send a message via Yahoo to Shattered Skies
Default

Eh, I knew lack of sleep would kill me. I just changed:
Code:
private JMenuBar menubar;
to

Code:
private JMenuBar menubar = new JMenuBar();
and the thing loaded up fine. Now its just a matter of getting the rest of the errors worked out when clicking on something in the menu.

Glad Im not doing anything at work today.

Thanks
Shattered Skies is offline  
Old 01-03-2007, 08:43 AM   #4 (permalink)
Orc's Breathmint
 
Renamation's Avatar
 
Join Date: Jan 2007
Location: -->>Alleria<<--
Posts: 105
Reputation: 10
Send a message via AIM to Renamation Send a message via Yahoo to Renamation
Default quote

Quote:
Originally Posted by ractoc View Post
Very simple:
You define an instance variable called menuBar. You don't initialise it though. But you DO call a member method on it on line 84.
yes.. this is correct, i found that out myself
__________________
.::::::What dosent kill you, makes you stronger::::::.
Go to my freaking web site renamation.tripod.com/ga

Renamation is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:12 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0
OnRPG, Copyright ©2003-2011, Game Entertainment Enterprises