Solved

Parameters in Java2 applet

Posted on 2002-07-19
20
1,025 Views
Last Modified: 2013-11-23
Hello, I simply want to pass a parameter from the html
to the applet

the error the plg-in raises is this:
java.lang.NullPointerException

     at java.applet.Applet.getParameter(Unknown Source)

     at com.game.arena.LoadRooms.<init>(LoadRooms.java:24)

     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

     at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

     at java.lang.reflect.Constructor.newInstance(Unknown Source)

     at java.lang.Class.newInstance0(Unknown Source)

     at java.lang.Class.newInstance(Unknown Source)

     at sun.applet.AppletPanel.createApplet(Unknown Source)

     at sun.plugin.AppletViewer.createApplet(Unknown Source)

     at sun.applet.AppletPanel.runLoader(Unknown Source)

     at sun.applet.AppletPanel.run(Unknown Source)

     at java.lang.Thread.run(Unknown Source)


- I used the htmmlconverter (extended & windows only form)
- I was clearing the cache of the plg-in

the html that was generated is:

For brevity I cutted down:

....
<PARAM NAME = CODEBASE VALUE = "http://130.88.175.4:8080/jsp/game/WEB-INF/classes/" >

    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">
    <PARAM NAME="scriptable" VALUE="false">
    <PARAM NAME = nick VALUE ="<%=nick%>">


</APPLET>
</NOEMBED>
</EMBED>
</OBJECT>

<!--
<APPLET CODE = "com.game.arena.LoadRooms.class" CODEBASE = "http://130.88.175.4:8080/jsp/game/WEB-INF/classes/" WIDTH = 600 HEIGHT = 400>
<PARAM NAME = nick VALUE ="<%=nick%>">
</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->

....

I tried both "nick" & nick without the ""

The line 24 where the exception is raised is:
     public LoadRooms()
     {
          myNick = super.getParameter("nick");          
          try
          {
               roomCommunicator = new RoomCommunicator( me, myNick );
          }catch( RemoteException e )
          {
               e.printStackTrace();
          }
     
          c = getContentPane();

I tried with super and without it.

Please any ideas why the exception is raised ???
0
Comment
Question by:pouli
  • 11
  • 9
20 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 7164700
It probably won't like the '<' and the '>' in the parameter name. Why not put the <%%> back in the applet itself and just do:

<PARAM NAME="nick" VALUE ="=nick">

then in the applet:

String param = getParameter("nick");
if (param.indexOf("=") == 0){
  param = "<%" + param + "%>";
}
0
 

Author Comment

by:pouli
ID: 7165016
Sorry, probably I haven't made it clear.

In the JSP code the <%=nick%> is being translated into to a string that is being read form a database.

So the line:
<PARAM NAME = nick VALUE ="<%=nick%>">

is being translated to (for instance)

<PARAM NAME = nick VALUE ="George">

I am sure that the value is NOT being set to null by the JSP. I have double check this.





0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7165148
OK, so the applet's in a JSP page. Be careful here:

<PARAM NAME = nick VALUE ="<%=nick%>">

there should be no spaces. Try:

<PARAM NAME="nick" VALUE="<%=nick%>">
0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:pouli
ID: 7165198
The htmlconverter produced this.
I think (I am not 100% sure) I tried without spaces
I will try again.

Why then the htnlconverter produces spaces?

Thank you for the comment
I will try again
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7165212
>>Why then the htnlconverter produces spaces?

Well AFAIK, there shouldn't be any. Maybe it doesn't matter!
0
 

Author Comment

by:pouli
ID: 7165226
any ideas then why the NullPointer is raised ?
Do you think it may a bug ???
I will search on the bug databases
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7165240
I wouldn't start looking yet! Try substituting <%=nick%> with a more verbose version. Can't think what the more verbose versions are at the moment :-)
0
 

Author Comment

by:pouli
ID: 7165259
I think I found something :-)
here it is

http://developer.java.sun.com/developer/bugParade/bugs/4317835.html

I will try the workaround and come back to you

0
 

Author Comment

by:pouli
ID: 7165289
The generated html file is :



<html>
<head>
<title>
myNickName Welcome Back!
</title>
</head>
<body>

<OBJECT
    classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = 600 HEIGHT = 400  
    codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4-win.cab#Version=1,4,0,0">
    <PARAM NAME = CODE VALUE = "com.game.arena.LoadRooms.class" >
<PARAM NAME = CODEBASE VALUE = "http://130.88.175.4:8080/jsp/game/WEB-INF/classes/" >

    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">
    <PARAM NAME="scriptable" VALUE="false">
    <PARAM NAME = "nick" VALUE  ="myNickName">

    <COMMENT>
          <EMBED type="application/x-java-applet;version=1.4" CODE = "com.game.arena.LoadRooms.class" CODEBASE = "http://130.88.175.4:8080/jsp/game/WEB-INF/classes/" WIDTH = 600 HEIGHT = 400 nick = "myNickName" scriptable=false pluginspage="http://java.sun.com/products/plugin/index.html#download">            
               <NOEMBED>
               </NOEMBED>
          </EMBED>
    </COMMENT>
</OBJECT>

<APPLET CODE = "com.game.arena.LoadRooms.class" CODEBASE = "http://130.88.175.4:8080/jsp/game/WEB-INF/classes/" WIDTH = 600 HEIGHT = 400>
<PARAM NAME="nick" VALUE="myNickName">
</APPLET>



</body>
</html>

As you can see the variable is being correctly substituted.

Unfortunately the error is still there.
The only change is that now the plg-in produces 2 times the NullPointerExctpion:

Java(TM) Plug-in: Version 1.4.0
Using JRE version 1.4.0 Java HotSpot(TM) Client VM
.....
----------------------------------------------------
java.lang.NullPointerException

     at java.applet.Applet.getParameter(Unknown Source)

     at com.game.arena.LoadRooms.<init>(LoadRooms.java:24)

     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

     at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

     at java.lang.reflect.Constructor.newInstance(Unknown Source)

     at java.lang.Class.newInstance0(Unknown Source)

     at java.lang.Class.newInstance(Unknown Source)

     at sun.applet.AppletPanel.createApplet(Unknown Source)

     at sun.plugin.AppletViewer.createApplet(Unknown Source)

     at sun.applet.AppletPanel.runLoader(Unknown Source)

     at sun.applet.AppletPanel.run(Unknown Source)

     at java.lang.Thread.run(Unknown Source)

java.lang.NullPointerException

     at java.applet.Applet.getParameter(Unknown Source)

     at com.game.arena.LoadRooms.<init>(LoadRooms.java:24)

     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

     at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

     at java.lang.reflect.Constructor.newInstance(Unknown Source)

     at java.lang.Class.newInstance0(Unknown Source)

     at java.lang.Class.newInstance(Unknown Source)

     at sun.applet.AppletPanel.createApplet(Unknown Source)

     at sun.plugin.AppletViewer.createApplet(Unknown Source)

     at sun.applet.AppletPanel.runLoader(Unknown Source)

     at sun.applet.AppletPanel.run(Unknown Source)

     at java.lang.Thread.run(Unknown Source)


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7165308
Curious! But notice that in:

<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">
<PARAM NAME="scriptable" VALUE="false">
<PARAM NAME = "nick" VALUE  ="myNickName">

there are spaces in the 'nick' parameter
0
 

Author Comment

by:pouli
ID: 7165334
I changed it. Nothing
I double checked all the spaces.
Seems like it doesn't matter.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7165385
What does the JSP look like around that area?
0
 

Author Comment

by:pouli
ID: 7165443
I just commented that line for now. The getParameter

I saw that the call to the remote object is being done twice although in the applet is clearly made only once.

Is this a bug ?

0
 

Author Comment

by:pouli
ID: 7165447
I think I found the problem with the getParameter.

The problem is that I call the new LoadRooms() from the init()
method and we should not call getParameter in the init() method.

I haven't checked it yet but probably this is the problem.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7165462
>>we should not call getParameter in the init() method.

True!
0
 

Author Comment

by:pouli
ID: 7165532
I think that I am experiencing some cache problems and it really gives it to my brain!

I have cleared the temporary internet folder
I cleared the cache from the control panel of the plg-in

I restarted.

What else ?

I am thinking this because I placed some System.out before calling the constructor of the new LoadRooms in the start() method of the applet but I cannot see it in the console.

I added a system.out in the init as well but I cannot see this as weel.

What is hapening ?

The exception remains the same without change.

So I think it is cache.
any idea hwo to overcome this ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7165545
Yes, you have to be careful of client-side caching. Server-side too!
0
 

Author Comment

by:pouli
ID: 7165562
Damn, nop
wrong
I haven't see the System.out that I have told you before BUT

I changed the LoadRooms constructor to someting like this

LoadRooms()
{

   System.out.println("This is changed");


   ...
   Continue with the code

and unfortunately the output of the console changed. The line of the exeption changed and the "This is changed" has been printed.

Damn.
Sorry, for the flooding of the messages. I am just trying to find out what is happening


0
 
LVL 86

Accepted Solution

by:
CEHJ earned 70 total points
ID: 7165565
That's OK- think in print - Xperts pretty quiet otherwise :-)
0
 

Author Comment

by:pouli
ID: 7166576
I foudn the problem :-)

When I was calling new LoadRooms() from the start() method it was executing the constructor of the applet!

That is why it wasn't ready to accept the getParameter.

I placed an empty constructor and changed the name of the previous method to soemthing else.

This is why I had the sideeffect of execuring twice.

Thank you for your time.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript/Java - Changing an image background color 4 66
more than one jdk and one jre 1 41
couple of eclipse 5 36
windows explorer path to command prompt 5 44
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question