Solved

Unhandled exception type ClassNotFoundException : with ObjectInputStrem

Posted on 2006-11-12
5
1,856 Views
Last Modified: 2012-08-14
I don't undertand why is this giving me Unhandled exception type ClassNotFoundException on command =  (String)dstObj.readObject(); ?

import java.io.IOException;
import java.io.InputStream;
import java.io.PipedOutputStream;
import java.io.ObjectInputStream;

public class Mystream implements Runnable {

      private InputStream in;
      
      public Mystream(PipedOutputStream srcPri, InputStream in)
      {

            this.in = in;
            
      }
      public void run()
      {
            try{
                  
                  ObjectInputStream dstObj = new ObjectInputStream(in);
                  
                  String command = null;
                  
                  //recieve a command
                  command =  (String)dstObj.readObject();
                  
                  //do something
                  System.out.print("TA doing something");
                  
            }catch(IOException e){
                  e.printStackTrace();
            }
            
      }
}
0
Comment
Question by:polkadot
  • 4
5 Comments
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17925459
> I don't undertand why is this giving me Unhandled exception type
> ClassNotFoundException on command =  (String)dstObj.readObject(); ?

because ObjectInputStream.readObject() throws ClassNotFoundException as well
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17925464
0
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 500 total points
ID: 17925469
>      public void run()
>      {
>           try{

>                ObjectInputStream dstObj = new ObjectInputStream(in);

>                String command = null;

>                //recieve a command
>                command =  (String)dstObj.readObject();

>                //do something
>                System.out.print("TA doing something");

>           }catch(IOException e){
>                e.printStackTrace();
>           }

>      }


should be


     public void run()
     {
          try{
               
               ObjectInputStream dstObj = new ObjectInputStream(in);
               
               String command = null;
               
               //recieve a command
               command =  (String)dstObj.readObject();
               
               //do something
               System.out.print("TA doing something");
               
          }catch(IOException e){
               e.printStackTrace();
          }
            catch(ClassNotFoundException e) {
                e.printStackTrace();
            }
         
     }
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17925488
Off topic: Ajay-Singh, congratulations! You hit the hall of fame in 10 months!

;JOOP!
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17925531
thanks sciuriware :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
print map entry 34 72
Tomcat: Unable to run tomcat service. 2 23
Java basic valueOf question 1 29
collection output issue 9 37
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 Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

828 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