> 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/
> 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
>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.