Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

I dont know why 'Null Exception' error.

Thread view: 
Ahn SeungRye - 12 Oct 2005 12:09 GMT
my 'Menu' class
------
class Menus{
    private JMenu jMenu;
    private JMenuItem jMenuItem;
   
    PublicNoteMenu(String menu){
        jMenu = new JMenu(menu);
    }
   
    public void addSeparator(){
        jMenu.addSeparator();
    }
   
    public void setMenuItem(String item){
        jMenuItem = new JMenuItem(item);
        jMenu.add(jMenuItem);
    }
   
    public JMenu returnJMenu(){
        return jMenu;
    }
   
    public JMenuItem returnJMenuItem(){
        return jMenuItem;
    }
}
------

and my main class is
.
.
private Menus MyMenu;
.
.
<setMenu Method>
        MyMenu = new PublicNoteMenu("File");
        MyMenu.setMenuItem("New");
        MyMenu.setMenuItem("Open");
        MyMenu.setMenuItem("Save");
        MyMenu.addSeparator();
        MyMenu.setMenuItem("Quit");
       
(err)        jMenubar.add(MyMenu.returnJMenu());
------

why 'jMenubar.add(MyMenu.returnJMenu());' line make err?
I think MyMenu.returnJMenu() has no problem...

anyone talk to me, what is my problem?
Timbo - 12 Oct 2005 12:23 GMT
> private Menus MyMenu;
> .
[quoted text clipped - 14 lines]
>
> anyone talk to me, what is my problem?

My guess is that either jMenubar as not been initialised or
MyMenu.returnJMenu() returns a null reference. What does the stack
trace say?
jonck - 12 Oct 2005 12:28 GMT
> anyone talk to me, what is my problem?

Please post your entire code, at the moment it does not make any sense
whatsoever. Your "main" class is certainly not "private Menus MyMenu",
since this is not how a class is denoted. Nor is it your "main method",
since this has the structure
public static void main(String args[]) {
}

So please clarify. Also you might want to move this thread over to
comp.lang.java.help, since this is obviously a newby question.

Kind regards, Jonck
Ahn SeungRye - 12 Oct 2005 12:30 GMT
Wed, 12 Oct 2005 04:28:08 -0700¿¡, jonck ½è½À´Ï´Ù:
..
>> anyone talk to me, what is my problem?
>
[quoted text clipped - 9 lines]
>
> Kind regards, Jonck
Thomas Weidenfeller - 12 Oct 2005 12:33 GMT
> my 'Menu' class
> ------
[quoted text clipped - 5 lines]
>         jMenu = new JMenu(menu);
>     }

Please show us real code. Not this junk. What you posted doesn't match
at all. You say you have a 'Menu' class, but your class is called
'Menus' (with an 's'), but even worth you claim the 'Menus" class has a
constructor 'PublicNoteMenu'.

>    
>     public void addSeparator(){
[quoted text clipped - 5 lines]
>         jMenu.add(jMenuItem);
>     }

You call that method multiple times. Each time the old jMenuItem
instance variable is overwritten. That doesn't make much sense.

>    
>     public JMenu returnJMenu(){
[quoted text clipped - 10 lines]
> .
> .

> private Menus MyMenu;
> .
> .
> <setMenu Method>
>         MyMenu = new PublicNoteMenu("File");

Really? Is PublicNoteMenu a subclass of Menus?

>         MyMenu.setMenuItem("New");
>         MyMenu.setMenuItem("Open");
[quoted text clipped - 6 lines]
>
> why 'jMenubar.add(MyMenu.returnJMenu());' line make err?

Since you are not showing us your real code we can't tell. Maybe you
never initialized jMenubar.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Ahn SeungRye - 12 Oct 2005 12:49 GMT
sorry about my tharead..

becaouse I dont know comp.lang.java.help,
and I moved my thread to comp.lang.java.help.

again really sorry about my thread...

Wed, 12 Oct 2005 13:33:41 +0200¿¡, Thomas Weidenfeller ½è½À´Ï´Ù:

>> my 'Menu' class
>> ------
[quoted text clipped - 62 lines]
>
> /Thomas
Roedy Green - 12 Oct 2005 13:07 GMT
>class Menus{   
...
>    PublicNoteMenu(String menu){
>        jMenu = new JMenu(menu)
...
>        MyMenu = new PublicNoteMenu("File");

This could not have compiled. The constructor must have the same name
as the class.

Please post your actual code.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.