Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IE4:"load:myclassapplet can't be instantiated!

Posted on 1998-06-24
11
Medium Priority
?
233 Views
Last Modified: 2006-11-17
This is the answer from the browser when I run my applet with Internet Explorer 4.0.
When I run it with Internet Explorer 3.0.2, the answer is : Exception : java.lang NullPointerException.
What method is able to cause this?

There are questions without answer:

I work on a LAN with an NT server, my webs are on the disk "Apps sur 'serveur1'(F:)" from the server and I not sure that it is the same thing that webs on the Internet.

thank you for your help.
0
Comment
Question by:thibal
[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
  • 6
  • 5
11 Comments
 

Author Comment

by:thibal
ID: 1223603
Edited text of question
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1223604
java.lang.NullPointerException mostly occurs when when you try to invoke a method on
an object that has not been instantiated and is actually null, like in the following example:

String aString = null;
String bString =  aString.toUpperCase(); // = null.toUpperCase() -> NullPointerException

Try to find the exact line where the exception occurs and verify with, for example a "if null
print something" that the problem is well as a I describe it. If yes, the question you have
to ask you if "why is this class instance actually null?". If this causes you problems, please
post the relevant piece of code with a pointer to the line and I will give you a more precise
answer.
0
 

Author Comment

by:thibal
ID: 1223605
Here is the code of my applet class. You can see the other class (server etc...)on my 2nd question "can't connect to ...".
But I think the problem is not there.
You recently propose me to use 'getDocumentBase()' but I suppose that the applet find this URL but I am not sure that this URL is the server one.

import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import StreamListener;

public class Exemple3 extends Applet
{
   public static final int Port=1548;
   URL serverURL=getDocumentBase();
   Socket s;
   DataInputStream in;
   PrintStream out;
   TextField inputfield;
   TextArea outputarea;
   StreamListener listener;

   public void init()
   {
try
{
   s = new Socket(serverURL.getHost(),Port);
   in = new DataInputStream(s.getInputStream());
   out = new PrintStream(s.getOutputStream());
   inputfield = new TextField();
   outputarea = new TextArea();
   outputarea.setEditable(false);
   this.setLayout(new BorderLayout());
   this.add("North",inputfield);
   this.add("Center",outputarea);

   listener = new StreamListener(in, outputarea);

   this.showStatus("Connnected to " 
   + s.getInetAddress().getHostName()
   + " : " +s.getPort());
   }
   catch (IOException e)
   {
this.showStatus(e.toString());
   }
}

   public boolean action(Event e, Object what)
   {
  if (e.target==inputfield)
           {
   out.println((String)e.arg);
   inputfield.setText("");
   return true;
   }
   return false;
   }
}
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Author Comment

by:thibal
ID: 1223606
In the try :
I change in comments lines "s = new socket...", "in = new DataInputStream..."," out = new PrintStream(..)", "this.showStatus...".

The result is the same.  
When I change in comments "URL serverURL=getDocumentBase()", there is no more problem. So I have a correct program which do nothing. Cool!
0
 
LVL 5

Accepted Solution

by:
fontaine earned 240 total points
ID: 1223607
The problem is that you are invoking getDocumentBase() at a place where the Applet class
has bot already been instantiated. So, the VM does not know about getDocumentBase().
Replace:

URL serverURL=getDocumentBase();

by:

URL serverURL=null;

and initialize the URL in the init() method:

public void init()  {
  try  {
         serverURL=getDocumentBase();
         s = new Socket(serverURL.getHost(),Port);


0
 
LVL 5

Expert Comment

by:fontaine
ID: 1223608
Comme cela, je crois que ton programme est encore plus cool! :-)
0
 

Author Comment

by:thibal
ID: 1223609
Fontaine, I want the question to be understandable for everyone,
so I try to write it in english.
I will give you the points when I this program will be running.
I had already try what you purpose but of course the URL found is the path of the directory where is the applet etc...
This applet is not really charged from the server because it is a common disk on server for all machine. So I think it is not the same on the Internet.
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1223610
I have tested the change on my system, and your applet is working just fine. I tested it served
from my Web server. From the local disk, it will indeed not work (like this). If you want to
have it working from the local disk, the best is to turn it in an app. and use the host name
(not the IP otherwise we are one step back) to identify the server. If you need help to go
into this direction, don't hesitate.

Note: Mon commentaire en Francais etais juste un clin d'oeil. Pour une fois que je croise un
francophone sur le Net... :-))
0
 

Author Comment

by:thibal
ID: 1223611
see you Email!
0
 

Author Comment

by:thibal
ID: 1223612
Adjusted points to 65
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1223613
It is rare to see points increasing just before grading! Thanks.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

705 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