Solved

Unhandled exception type ClassNotFoundException : with ObjectInputStrem

Posted on 2006-11-12
5
1,788 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
Comment Utility
> 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
Comment Utility
0
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 500 total points
Comment Utility
>      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
Comment Utility
Off topic: Ajay-Singh, congratulations! You hit the hall of fame in 10 months!

;JOOP!
0
 
LVL 23

Expert Comment

by:Ajay-Singh
Comment Utility
thanks sciuriware :)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

743 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

16 Experts available now in Live!

Get 1:1 Help Now