?
Solved

Unhandled exception type ClassNotFoundException : with ObjectInputStrem

Posted on 2006-11-12
5
Medium Priority
?
1,922 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Accepted Solution

by:
Ajay-Singh earned 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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