473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

What can i do with this error “java.io.NotSerializableException”?

1
i am working on a java project and i want in the begging of the programme to load the things from the file and then add some things... I am getting this error

Expand|Select|Wrap|Line Numbers
  1. "java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException:      pcshop.Pc 
  2.  
  3. at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
  4. at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
  5. at java.util.ArrayList.readObject(ArrayList.java:733)
  6. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  7. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  8. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  9. at java.lang.reflect.Method.invoke(Method.java:601)
  10. at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
  11. at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)
  12. at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
  13. at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
  14. at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
  15. at pcshop.PcShop.loadPcFiles(PcShop.java:48)
  16. at pcshop.PcShop.main(PcShop.java:212)
  17.   Caused by: java.io.NotSerializableException: pcshop.Pc
  18. at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
  19. at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
  20. at java.util.ArrayList.writeObject(ArrayList.java:710)
  21. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  22. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  23. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  24. at java.lang.reflect.Method.invoke(Method.java:601)
  25. at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
  26. at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
  27. at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
  28. at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
  29. at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
  30. at pcshop.PcShop.main(PcShop.java:255)"
I am gonna give you some code..
Expand|Select|Wrap|Line Numbers
  1. //add the elements to an array list
  2. public static void Insert()
  3.                          Pc pc1=new Pc();
  4.                          System.out.println("Price: \n");
  5.                          n=in.nextFloat();
  6.                          pc1.setPrice(n);
  7.                          System.out.println("Quantity: \n");
  8.                          m=in.nextInt();
  9.                          pc1.setQuantity(m);
  10.                          pcList.add(pc1);//pcList is an array list of Pc class
  11.  }
  12.  //load the file
  13.   public static void loadPcFiles()
  14. {
  15.   try{
  16.  
  17.  
  18.   FileInputStream input1=new FileInputStream("Users.txt");
  19.  
  20.   ObjectInputStream ob1=new ObjectInputStream(input1);
  21.   //pcList is an array list of PC
  22.   pcList =( ArrayList<Pc>) ob1.readObject();
  23.  
  24.  
  25.   ob1.close();
  26.  
  27.   input1.close();
  28.  
  29.   } catch (ClassNotFoundException e) {
  30.           e.printStackTrace();
  31.   } catch(FileNotFoundException e) {
  32.            e.printStackTrace();
  33.    } catch (IOException e) {
  34.   e.printStackTrace();}
  35.  }
  36.  
  37. //print the lements from the arraylist
  38. private static void PrintProducts ()
  39. {
  40. System.out.println("---------------------");
  41. System.out.println("|  pc              :  |\n");
  42. System.out.println("---------------------");
  43.    for(Pc A: pcList)
  44.    {
  45.  
  46.        A.printPc();
  47.    }
  48.  }
  49.  
  50. //PC class
  51. public class Pc  extends Products implements Serializable {
  52.  
  53.  private String type;
  54.  private float frequency;
  55.  
  56.  public Pc() {}
  57.  
  58. public Pc(String type, float frequency) {
  59.     this.type = type;
  60.     this.frequency = frequency;
  61. }
  62.  //and the products class
  63.  public class Products implements Serializable{
  64.  
  65. private float price;
  66. private int quantity;
  67. private int id;
  68. private String description;
  69.  
  70. public Products(){}
  71.  
  72. public String getDescription() {
  73.     return description;
  74. }
  75.  
  76. public void setDescription(String description) {
  77.     this.description = description;
  78. }
  79.  
  80. public float getPrice() {
  81.     return price;
  82. }
  83.  
  84. public void setPrice(float price) {
  85.     this.price = price;
  86. }
  87.  
  88. public int getQuantity() {
  89.     return quantity;
  90. }
  91.  
  92. public void setQuantity(int quantity) {
  93.     this.quantity = quantity;
  94. }
  95.  
  96. public int getId() {
  97.     return id;
  98. }
  99.  
  100. public void setId(int id) {
  101.     this.id = id;
  102. }
  103.  
  104.  @Override
  105.  public String toString() {
  106.      return "Products{" + "price=" + price + ", quantity=" + quantity + ", id=" + id +        ", description=" + description + '}';
  107. }
  108.  
  109.  
  110.  
  111. }
  112.  
  113.  
  114. public float getFrequency() {
  115.     return frequency;
  116. }
  117.  
  118. public void setFrequency(float frequency) {
  119.     this.frequency = frequency;
  120. }
  121.  
  122. public String getType() {
  123.     return type;
  124. }
  125.  
  126. public void setType(String type) {
  127.     this.type = type;
  128. }
  129.  
  130.  public void printPc()
  131.  {
  132.   System.out.println("Price: "+getPrice()+"Quantity"+getQuantity());
  133.  
  134.   System.out.println("---------------------");
  135.  }
  136.  
  137.  @Override
  138. public String toString() {
  139.     return "Pc{" + "type=" + type + ", frequency=" + frequency + '}';
  140.  }
Why do i get an NotSerializable error even though my classes are serializabled??Does anyone now?
May 22 '12 #1
1 2664
Have you tried running in debug mode to see where the break occurs?
May 23 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jochen Daum | last post by:
Hi, I have to emulate a "file upload" to a Java Servlet which is done with the class URLConnection. The java source basically does URLConnection conn =...
1
by: Matt | last post by:
I run the xalan-java v2.60 command line: java org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -out test.html But it has the following error: (Location of error unknown)XSLT Error...
6
by: Matt Bostock | last post by:
Hi, When I validate this page: http://www.drfunkenstein.net/using http://jigsaw.w3.org/css-validator/, I get the following results: ...
0
by: Jon LaRosa | last post by:
Hi all - I have a web application and I want to be able to do some basic error handling. For example, here is one error I would like to catch and display in a useful way for the user:...
3
by: Stefan Mueller | last post by:
Because the characters ', ", ... make troubles in my input boxes I use the following PHP command while generating the page htmlentities($my_var, ENT_QUOTES); However, if I use in my java scripts...
6
by: Stefan Mueller | last post by:
I read data (e.g. äöüÄÖÜçéàè"') from my MySQL database which I'd like to show in an input box. <?php $mysql_data = "äöüÄÖÜçéàè\"'"; $html_data = addslashes(htmlentities($mysql_data,...
2
by: chokcheese | last post by:
I'm having trouble with a java application. When I try and run the program it shows a java.lang.NullPointerException in the "tic.getClient().getClientTicketList().add(tic);" line (it's in bold). I...
2
by: cloudy | last post by:
First at all, i'm sorry, i not good in writing english. i want to retrieve a string from my applet via Javascript. I use a method named ReadAll. public String ReadAll(String StrOut, String...
13
by: falconsx23 | last post by:
Hi, I need help with my java program. I am new with java, so go easy on me if this is a dumb question. Ok the question is "You will complete two methods for this exercise. The headers (and a...
3
by: makweatan | last post by:
Hello guys... Data is not updated into table. I got this error : java.lang.NullPointerException 00000030 SystemErr R java.lang.NullPointerException 00000030 SystemErr R at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.