Solved

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

Posted on 1998-06-24
11
185 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
  • 6
  • 5
11 Comments
 

Author Comment

by:thibal
Comment Utility
Edited text of question
0
 
LVL 5

Expert Comment

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

Author Comment

by:thibal
Comment Utility
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 60 total points
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 5

Expert Comment

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

Author Comment

by:thibal
Comment Utility
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
Comment Utility
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
Comment Utility
see you Email!
0
 

Author Comment

by:thibal
Comment Utility
Adjusted points to 65
0
 
LVL 5

Expert Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:

728 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

10 Experts available now in Live!

Get 1:1 Help Now