Solved

Unhandled exception type ClassNotFoundException : with ObjectInputStrem

Posted on 2006-11-12
5
1,835 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
factorial example 4 40
fibonacci ten numbers 4 38
table example 4 29
Which non-HTML GUI front end to use with Java? 3 22
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

773 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