Solved

Parameters in Java2 applet

Posted on 2002-07-19
20
1,018 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:pouli
Comment Utility
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
Comment Utility
>>Why then the htnlconverter produces spaces?

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

Author Comment

by:pouli
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

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

Expert Comment

by:CEHJ
Comment Utility
What does the JSP look like around that area?
0
 

Author Comment

by:pouli
Comment Utility
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
Comment Utility
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
Comment Utility
>>we should not call getParameter in the init() method.

True!
0
 

Author Comment

by:pouli
Comment Utility
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
Comment Utility
Yes, you have to be careful of client-side caching. Server-side too!
0
 

Author Comment

by:pouli
Comment Utility
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
Comment Utility
That's OK- think in print - Xperts pretty quiet otherwise :-)
0
 

Author Comment

by:pouli
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 84
wordlen challenge 3 46
eclipse package explorer vs project explorer view 2 27
recursion example 16 68
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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now