Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java 1.x panels and addNotify() ??

1 view
Skip to first unread message

Laszlo

unread,
Jul 31, 1996, 3:00:00 AM7/31/96
to

I've been "putting up" with this since I got cafe. I thought the upgrade
to 1.20 would fix this. Since it didn't, now I'm wondering whether it's me.

When using building/editing resources in Cafe Studio, whenever I save
ANYthing, it goes back through all my project's Panels and sticks in a
call to addNotify(). Since it does this to the Frames and Dialogs the
panels are being added to ANYway, I've been going through by hand and
commenting out the Panels' addNotify() calls. Everything seems to work.

If I DON'T take out all the addNotify() calls from the Panels, trying to
execute the applet results in an immediate "null parent" (or something
like that) error.

Do I just not have a clue? Should addNotify() be there? Or is there a way
to get Cafe to stop sticking it in there?

Thanks much!
Laszlo

--

Government out of Internet!!!!

Laszlo las...@CoSite.com San Francisco
"Here we are, born to be kings, we're the princes of the universe" -Queen

My opinions are mine alone, not necessarily those of my employer.

Aaron Inami

unread,
Aug 6, 1996, 3:00:00 AM8/6/96
to

Laszlo wrote:
>
> I've been "putting up" with this since I got cafe. I thought the upgrade
> to 1.20 would fix this. Since it didn't, now I'm wondering whether it's me.
>
> When using building/editing resources in Cafe Studio, whenever I save
> ANYthing, it goes back through all my project's Panels and sticks in a
> call to addNotify(). Since it does this to the Frames and Dialogs the
> panels are being added to ANYway, I've been going through by hand and
> commenting out the Panels' addNotify() calls. Everything seems to work.
>
> If I DON'T take out all the addNotify() calls from the Panels, trying to
> execute the applet results in an immediate "null parent" (or something
> like that) error.
>
> Do I just not have a clue? Should addNotify() be there? Or is there a way
> to get Cafe to stop sticking it in there?
>
> Thanks much!
> Laszlo
>

I have pulled my hair out trying to figure this one. See below for
complete details.
These are messages that went back and forth between me and an engineer
at Sun.
I was going to send this one to D'arcy when we received our company's
copy of Cafe.


------------------------------------------------------------------------------------
From: Sheree Neoh
Sent: Tuesday, August 06, 1996 12:45 PM
To: 'Aaron Inami'
Subject: RE: REVISED Java Question

I can't tell from this what is wrong, but it feels like the same
problem.
Some variable that the init method of
sun.awt.win32.MComponentPeer.<init>
(MComponentPeer.java is expecting to be non-null is null. That usually
means that
something higher up is improperly initialized, or uninitialized. I'm
not familiar enough with Java to know what a proper applet ought to look
like, but that'd be my guess.

To say it another way, in order to do what you are trying to do, you
need to
do A, then B, then C then call addNotify. You're doing A, you're doing
C,
but you've forgotten or incorrectly done B, and so when you call
addNotify,
it doesn't get the environment it expects, and dies. You need to figure
out what B is. --Tom

------------------------------------------------------------------------------
From: Aaron Inami
Sent: Tuesday, August 06, 1996 11:33 AM
To: 'Sheree Neoh'
Subject: RE: REVISED Java Question

Sheree,

Please forward this back to your contact.

Thanks,
Aaron

I HAVE LOOKED AT MY CODE AGAIN. I HAVE TRIED SEVERAL THINGS. I EVEN
DID A
setLayout(new FlowLayout()). IT SEEMS THAT A SUBCLASS OF Panel WILL NOT
INITIALIZE IF THERE IS AN addNotify() IN THE CONSTRUCTOR METHOD. THE
ONLY
WAY I CAN GET THE CLASS TO WORK IS IF I REMOVE THE addNotify() FROM THE
CONSTRUCTOR EVENT. WHEN I DO THIS, THE reshape() METHOD FOR Choice
OBJECTS IN
THE CONSTRUCTOR METHOD OF THE SUBCLASS OF Panel WILL NOT WORK IN MOST
JAVA
INTERPRETERS (with the exception of Netscape 3.0). I END UP HAVING TO
DO A
reshape() AFTER THE SUBCLASS OF Panel HAS BEEN ADDED - add(panel1) - TO
THE
PARENT APPLET OR FRAME.


THIS IS THE STACK REPORT:

java.lang.NullPointerException: null parent
at sun.awt.win32.MComponentPeer.<init>(MComponentPeer.java:86)
at sun.awt.win32.MCanvasPeer.<init>(MCanvasPeer.java:29)
at sun.awt.win32.MPanelPeer.<init>(MPanelPeer.java:26)
at sun.awt.win32.MToolkit.createPanel(MToolkit.java:129)
at java.awt.Panel.addNotify(Panel.java:46)
at test_panel.<init>(test_panel.java:27)
at test.init(test.java:48)
at sun.applet.AppletPanel.run(AppletPanel.java:259)
at java.lang.Thread.run(Thread.java:294)


THE ERROR HAPPENS WHEN THE VARIABLE IS INSTANTIATED:

public class test extends Applet {
test_panel panel1 = new test_panel();

// ...
// Misc code
// ...


}

HERE IS THE CLASS:
(line numbers from the stack report are not correct because I have
remove
leading and trailing comment lines)


import java.awt.*;

public class test_panel extends Panel {

public test_panel() {

super();

//{{INIT_CONTROLS
setLayout(new FlowLayout());
//ERROR HAPPENS HERE ON NEXT LINE
addNotify();
resize(insets().left + insets().right + 399, insets().top +
insets().bottom + 195);
group1= new CheckboxGroup();
label1=new Label("Label");
label1.setFont(new Font("Helvetica",Font.BOLD,14));
add(label1);
label1.reshape(insets().left + 14,insets().top + 11,52,19);
edit1=new TextField(10);
add(edit1);
edit1.reshape(insets().left + 75,insets().top + 8,89,24);
check1=new Checkbox("Radio button",group1, false);
add(check1);
check1.reshape(insets().left + 186,insets().top + 80,90,15);
choice1= new Choice();
add(choice1);
choice1.reshape(insets().left + 222,insets().top + 102,72,60);
choice1.addItem("sadf");
choice1.addItem("asdfsda");
choice1.addItem("sadf");
choice1.addItem("sdaf");
choice1.addItem("sdaf");
move_choice=new Button("move choice");
add(move_choice);
move_choice.reshape(insets().left + 29,insets().top +
122,85,21);
//}}


}

public boolean handleEvent(Event event) {
if (event.id == Event.ACTION_EVENT && event.target ==
move_choice) {
clickedMoveChoice();
return true;
}

return super.handleEvent(event);
}

//{{DECLARE_CONTROLS
CheckboxGroup group1;
Label label1;
TextField edit1;
Checkbox check1;
Choice choice1;
Button move_choice;
//}}

public void clickedMoveChoice() {
// to do: put event handler code here.
choice1.reshape(insets().left + 222,insets().top + 102,72,60);

}
}


-------------------------------------------------------------------------
From: Sheree Neoh
Sent: Monday, August 05, 1996 2:28 PM
To: 'Aaron Inami'
Subject: RE: REVISED Java Question

Here's the response I got from the guy.
Told him what you told me, too.
Sheree
Hope this helps.

My suspicion is that either you are missing the addNotify method
or that something is broken within it. Judging from the stack
trace, I'd go for the "something broken within it" side. But
it could be that you are not initializing the world properly or
that addNotify needs an argument. What it looks like is the
kind of error you get when you pass a C function an uninitialized
pointer to a string, and the function hasn't been written robustly
enough to check for that.

The obvious suspects are the "setLayout(null)" line and the
"addNotify()" line.
Maybe it needs a non-null layout? Maybe addNotify needs an argument?
Maybe
there's a missing initializer line? --Tom


-----------------------------------------------------------------------------------------
From: Aaron Inami
Sent: Wednesday, July 31, 1996 4:45 PM
To: 'Sherry Neoh'
Subject: REVISED Java Question

Hi Sherry,

Here is the REVISED question:

I have an applet class which resides in a html page. This applet class
has a button
which opens a frame class using the .show() method. This frame class
has a custom panel
class embedded in it.

I am getting NullPointException thrown when I try run this applet. What
am I doing wrong?

The error I receive is shown below:

java.lang.NullPointerException: null parent
at sun.awt.win32.MComponentPeer.<init>(MComponentPeer.java:86)
at sun.awt.win32.MCanvasPeer.<init>(MCanvasPeer.java:29)
at sun.awt.win32.MPanelPeer.<init>(MPanelPeer.java:26)
at sun.awt.win32.MToolkit.createPanel(MToolkit.java:120)
at java.awt.Panel.addNotify(Panel.java:46)
at Test_Panel.<init>(Test_Panel.java:27)
at Test_Frame.<init>(Test_Frame.java:29)
at pdr4.init(pdr4.java:53)
at sun.applet.AppletPanel.run(AppletPanel.java:243)
at java.lang.Thread.run(Thread.java:289)


I tried debugging and found that the error occured at the "addNotify"
method in the panel class.
When I remove the addNotify method, the error does not occur, but
objects in the panel are not
placed correctly.
NOTE: The only java interpreter that will display the objects correctly
is Netscape Navigator 3.0 beta (1-5).
All the others (Netscape Navigator 2.0, HotJava, Sun Java Appletviewer,
Microsoft Explorer 3.0 beta)
will not place the objects correctlly.
My classes are shown below.

public class pdr4 extends Applet {
Test_Frame frame1;

public void init() {
setLayout(null);
resize(281,190);
frame1 = new Test_Frame();
}

public void clickedButton1() {
frame1.show();
// to do: put event handler code here.
}
}

public class Test_Frame extends Frame {
Test_Panel panel1;

public Test_Frame() {

super("Test_Frame window");

setLayout(null);
addNotify();
resize(insets().left + insets().right + 505, insets().top +
insets().bottom + 361);
panel1=new Test_Panel();
panel1.setLayout(null);
add(panel1);
panel1.reshape(insets().left + 30,insets().top + 59,443,251);
}
}


public class Test_Panel extends Panel {
Label label1;

public Test_Panel() {

super();

setLayout(null);
addNotify();
resize(insets().left + insets().right + 394, insets().top +
insets().bottom + 208);
label1=new Label("Field A");
add(label1);
label1.reshape(insets().left + 10,insets().top + 11,46,21);
}
}

0 new messages