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 / December 2005

Tip: Looking for answers? Try searching our database.

Please Help???????????????????

Thread view: 
prasad.knvs@gmail.com - 27 Dec 2005 10:57 GMT
When executing a class file I keep on getting these errors:-

java.lang.NullPointerException
       at java.awt.Container.addImpl(Container.java:625)
       at java.awt.Container.add(Container.java:307)
       at ShareApp$RemindTask.run(ShareApp.java:60)
       at java.util.TimerThread.mainLoop(Timer.java:432)
       at java.util.TimerThread.run(Timer.java:

Can anyone help?

Prasad
Thomas Hawtin - 27 Dec 2005 11:22 GMT
> When executing a class file I keep on getting these errors:-

> java.lang.NullPointerException
>         at java.awt.Container.addImpl(Container.java:625)
>         at java.awt.Container.add(Container.java:307)
>         at ShareApp$RemindTask.run(ShareApp.java:60)
>         at java.util.TimerThread.mainLoop(Timer.java:432)
>         at java.util.TimerThread.run(Timer.java:

The most obvious reason would be that you are trying to add a null
Component reference. Have you looked at the line in Container.java of
whichever version of Java you are using?

Potentially it could be a threading issue. Although AWT is supposed to
be thread-safe, that is a little optimistic. Also application code may
not even attempt thread-safety. javax.swing.Timer is usually preferable
to java.util.Timer in GUI (even AWT) applications. Using setVisible is
probably better than adding and removing widgets, if possible.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Andrew Thompson - 27 Dec 2005 11:29 GMT
> Sub: Please Help???????????????????

This is a silly title, it makes you sound needy, and
there is no need for the repeat of '?'.

A better title might be
  NullPointerException in application
..or..
  fix NullPointerException?

> When executing a class file I keep on getting these errors:-
>
[quoted text clipped - 4 lines]
>         at java.util.TimerThread.mainLoop(Timer.java:432)
>         at java.util.TimerThread.run(Timer.java:

I gues the problem is the line mentioned which is not a Sun
class (unless this code has uncovered a bug).

That would be line 60 of 'ShareApp'.

> Can anyone help?

You might follow it up with the author of ShareApp, as,
without the code, there is little more than generic
advice that can be dispenced.  But that advice would be..
<http://mindprod.com/jgloss/runerrormessages.html#NULLPOINTEREXCEPTION>

As an aside, a better group for those learning Java is..
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew

Roedy Green - 27 Dec 2005 13:43 GMT
>java.lang.NullPointerException
>        at java.awt.Container.addImpl(Container.java:625)
>        at java.awt.Container.add(Container.java:307)
>        at ShareApp$RemindTask.run(ShareApp.java:60)
>        at java.util.TimerThread.mainLoop(Timer.java:432)
>        at java.util.TimerThread.run(Timer.java:

You are using an old version of Java, so line 625 is not the same
place as it is now. Check the source code in SRC.ZIP to tell which
parameter was null -- likely the component, possibly the constraints.

the code looks like this:

 protected void addImpl(Component comp, Object constraints, int
index) {
       synchronized (getTreeLock()) {
           /* Check for correct arguments:  index in bounds,
            * comp cannot be one of this container's parents,
            * and comp cannot be a window.
            * comp and container must be on the same GraphicsDevice.
            * if comp is container, all sub-components must be on
            * same GraphicsDevice.
            */
           GraphicsConfiguration thisGC =
this.getGraphicsConfiguration();

           if (index > ncomponents || (index < 0 && index != -1)) {
               throw new IllegalArgumentException(
                         "illegal component position");
           }
       if (comp instanceof Container) {
           for (Container cn = this; cn != null; cn=cn.parent) {
               if (cn == comp) {
               throw new IllegalArgumentException(
                     "adding container's parent to itself");
               }
           }
           if (comp instanceof Window) {
               throw new IllegalArgumentException(
                      "adding a window to a container");
           }
       }
       if (thisGC != null) {
           comp.checkGD(thisGC.getDevice().getIDstring());
       }

           /* Reparent the component and tidy up the tree's state. */
           if (comp.parent != null) {
               comp.parent.remove(comp);
                   if (index > ncomponents) {
                       throw new IllegalArgumentException("illegal
component position");
                   }
           }

           /* Add component to list; allocate new array if necessary.
*/
           if (ncomponents == component.length) {
               Component newcomponents[] = new Component[ncomponents
* 2 + 1];
               System.arraycopy(component, 0, newcomponents, 0,
ncomponents);
               component = newcomponents;
           }
           if (index == -1 || index == ncomponents) {
               component[ncomponents++] = comp;
           } else {
               System.arraycopy(component, index, component,
                                index + 1, ncomponents - index);
               component[index] = comp;
               ncomponents++;
           }
           comp.parent = this;

           adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
               comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
           adjustDescendants(comp.countHierarchyMembers());

           if (valid) {
               invalidate();
           }
           if (peer != null) {
               comp.addNotify();
           }
           
           /* Notify the layout manager of the added component. */
           if (layoutMgr != null) {
               if (layoutMgr instanceof LayoutManager2) {
((LayoutManager2)layoutMgr).addLayoutComponent(comp, constraints);
               } else if (constraints instanceof String) {
                   layoutMgr.addLayoutComponent((String)constraints,
comp);
               }
           }
           if (containerListener != null ||
               (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
               ContainerEvent e = new ContainerEvent(this,
                                    ContainerEvent.COMPONENT_ADDED,
                                    comp);
               dispatchEvent(e);
           }

comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
                                      this,
HierarchyEvent.PARENT_CHANGED,
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
           if (peer != null && layoutMgr == null && isVisible()) {
               updateCursorImmediately();
           }
       }
   }

   /**
    * Checks that all Components that this Container contains are on
    * the same GraphicsDevice as this Container.  If not, throws an
    * IllegalArgumentException.
    */
   void checkGD(String stringID) {
       Component tempComp;
       for (int i = 0; i < component.length; i++) {
           tempComp= component[i];
           if (tempComp != null) {
               tempComp.checkGD(stringID);
           }  
       }
   }

   /**
    * Removes the component, specified by <code>index</code>,
    * from this container.
    * This method also notifies the layout manager to remove the
    * component from this container's layout via the
    * <code>removeLayoutComponent</code> method.
    *
    * @param     index   the index of the component to be removed
    * @see #add
    * @since JDK1.1
    */
   public void remove(int index) {
       synchronized (getTreeLock()) {
           if (index < 0  || index >= ncomponents) {
               throw new ArrayIndexOutOfBoundsException(index);
           }
           Component comp = component[index];
           if (peer != null) {
               comp.removeNotify();
           }
           if (layoutMgr != null) {
               layoutMgr.removeLayoutComponent(comp);
           }

           adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
               -comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
-comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
           adjustDescendants(-(comp.countHierarchyMembers()));

           comp.parent = null;
           System.arraycopy(component, index + 1,
                            component, index,
                            ncomponents - index - 1);
           component[--ncomponents] = null;

           if (valid) {
               invalidate();
           }
           if (containerListener != null ||
               (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
               ContainerEvent e = new ContainerEvent(this,
                                    ContainerEvent.COMPONENT_REMOVED,
                                    comp);
               dispatchEvent(e);
           }

comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
                                      this,
HierarchyEvent.PARENT_CHANGED,
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
           if (peer != null && layoutMgr == null && isVisible()) {
               updateCursorImmediately();
           }
       }
   }

   /**
    * Removes the specified component from this container.
    * This method also notifies the layout manager to remove the
    * component from this container's layout via the
    * <code>removeLayoutComponent</code> method.
    *
    * @param comp the component to be removed
    * @see #add
    * @see #remove(int)
    */
   public void remove(Component comp) {
       synchronized (getTreeLock()) {
           if (comp.parent == this)  {
               /* Search backwards, expect that more recent additions
                * are more likely to be removed.
                */
               Component component[] = this.component;
               for (int i = ncomponents; --i >= 0; ) {
                   if (component[i] == comp) {
                       remove(i);
                   }
               }
           }
       }
   }

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



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



©2009 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.