Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: why i m not getting run time exception , though i supposed to get exception "Not serializable exception"

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post why i m not getting run time exception , though i supposed to get exception "Not serializable exception"

    import java.io.*;

    class Dog implements Serializable
    {

    Collar col;
    int dogSize;

    Dog(Collar c,int s)
    {

    col=c;
    dogSize=s;

    }

    public Collar getCollar()
    {
    return col;
    }

    }

    class Collar
    {

    int collarSize;

    //Collar theCollar;

    Collar(int s)
    {

    collarSize=s;
    }

    public int getCollarSize()
    {
    return collarSize;

    }

    }


    class Testcollar
    {

    public static void main (String [] args)
    {

    Collar thecollar = new Collar(3);
    Dog d=new Dog(thecollar,5);

    System.out.println(d.getCollar().getCollarSize());

    try
    {

    FileOutputStream fs= new FileOutputStream("tttestcollar.ser");

    ObjectOutputStream os=new ObjectOutputStream(fs);

    os.writeObject(d);

    os.close();


    }catch(Exception e){}


    try
    {

    FileInputStream fis=new FileInputStream("tttestcollar.ser");

    ObjectInputStream ois=new ObjectInputStream(fis);

    d=(Dog)ois.readObject();

    ois.close();


    }catch(Exception e){}

    System.out.println(d.getCollar().getCollarSize());


    }

    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,971
    My Mood
    Hungover
    Thanks
    133
    Thanked 554 Times in 475 Posts

    Default Re: why i m not getting run time exception , though i supposed to get exception "Not serializable exception"

    When posting code, please use the highlight tags to preserve formatting.

    Where do you expect to get that error?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: why i m not getting run time exception , though i supposed to get exception "Not serializable exception"

    i supposed to get an run time exception because my collar obect is not serialized, where as java says that u must get an runtime exception

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,971
    My Mood
    Hungover
    Thanks
    133
    Thanked 554 Times in 475 Posts

    Default Re: why i m not getting run time exception , though i supposed to get exception "Not serializable exception"

    I still can't read your code because it's unformatted, but I think I see some empty catch blocks. How would you even know if you were getting the Exception in the first place?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: why i m not getting run time exception , though i supposed to get exception "Not serializable exception"

    ok..i got it...if i call e.printStackTrace() , i get that exception with output

    --- Update ---

    A runtime exception because i have not serialized collar,though dog was serialized.

    --- Update ---

    A runtime exception because i have not serialized collar,though dog was serialized

Similar Threads

  1. Replies: 5
    Last Post: January 23rd, 2013, 04:29 PM
  2. Replies: 2
    Last Post: August 30th, 2012, 09:45 AM
  3. Replies: 3
    Last Post: December 7th, 2011, 01:03 AM
  4. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 07:35 AM