Solved

Unhandled exception type ClassNotFoundException : with ObjectInputStrem

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
My project did see openJDK that I installed. What could be the problem 7 122
topping3 challenge 14 69
create a gui in perl 3 70
Java / Linux and Regular Expressions 11 69
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

919 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