Solved

Parameters in Java2 applet

Posted on 2002-07-19
20
1,030 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java mysql insert application 14 68
Java array 10 89
Pass multiple values or string arrays in java as a parameter 3 74
Strange router problem - can't access hotmail.com 14 109
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

710 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