Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Start applet not initialised

 
Efua Aidoo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have compiled the following code and it compiles but when i run the code the following error message is shown in the applet window Start: Applet not initialized. Can someone please have a look at my code and say where I went wrong. Thanks

import java.net.*;
import java.io.*;

public class Clientvee
{
public static void main (String []args) throws IOException
{

Socket clientSocket;
PrintStream out = null;
BufferedReader in = null;
try
{
clientSocket = new Socket("192.168.254.2",1521);
out = new PrintStream(clientSocket.getOutputStream());
in=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
}
catch(UnknownHostException e)
{
System.err.println("Unidentified hostname");
System.exit(1);
}
catch(IOException e)
{
System.err.println("Couldn't get I/O");
System.exit(1);
}
BufferedReader stdin = new BufferedReader(new InputStreamReader((System.in)));
String login=in.readLine(); //read from socket
System.out.println(login);
String logName=stdin.readLine(); //accepting login
out.println(logName);
String password=in.readLine(); //reading from the socket
System.out.println(password);
String pass=stdin.readLine(); //accepting password
out.println(pass);
String str=in.readLine();
System.out.println(str);
while((str = stdin.readLine()) != null)
{
out.println (str);
if(str.equals("Bye"))
break;
}

out.close();
in.close();
stdin.close();
}
}

when you compile it does not give you any error.it compiles successfully but when you run it, it gives you the window and an error behind it in DOS mode. This is the error.

java.lang.ClassCastException:Clientvee cannot be cast to java.applet.Applet
at sun.applet.AppletPanel.createApplet <AppletPanel.java:778>
at sun.applet.AppletPanel.runLoader<AppletPanel.java:707>
at sun.applet.AppletPanel.run<AppletPanel.java:361>
at java.lang.Thread.run<Thread.java:619>

please help me out in solving this error.I know and believe that you can help me out.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

What you have there is not an applet (which extends the java.applet.Applet class), but an application (which includes a main method). The ApplicationApplet class can help run an application as an applet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic