1

I'm using Eclipse to create a simple project. I'm trying to implement Serializable in my Java class, but Eclipse is not recognizing it saying "Serializable cannot be resolved to a type" and offering me to create an inteface called Serializable.

public class Location implements Serializable {

Isn't Serializable supposed to be a built in interface? How do I get it to work?

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
  • 1
    There is no "built in interface" but there are automatic imports (`java.lang`). `Serializable` is in `java.io`, which is _not_ among the automatic imports? See answer from @Reimeus – fge Jan 03 '13 at 02:32

4 Answers4

7

You need to import it from the java.io package:

import java.io.Serializable;
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • So the other user who deleted his answer maybe was right. I suggest him/her to undelete. – gd1 Jan 03 '13 at 02:42
  • Strange....`java.io` is one of the core packages in Java, i.e. it's not an external library. – Reimeus Jan 03 '13 at 02:43
  • @gd1, I undeleted my answer. – user1329572 Jan 03 '13 at 02:43
  • 1
    @Imray can you restart Eclipse and see if it makes any difference? Failing that I'd say to install the latest JDK and install for Eclipse. – Reimeus Jan 03 '13 at 02:46
  • @Imray After adding the import statement, what is the exact error you receive? – arshajii Jan 03 '13 at 02:46
  • I was looking at my library, and I noticed that my it says "[unbound]" next to it. Could that have something to do with it? – CodyBugstein Jan 03 '13 at 02:54
  • Your JDK might be ok, in which case you can simply re-install it in Eclipse - [Instructions](http://stackoverflow.com/questions/3542051/eclipse-frustration-with-java-1-7-unbound-library). Otherwise I'd go for a new download. – Reimeus Jan 03 '13 at 02:57
3

You have to import java.io.Serializable.

If you click the "error icon" in Eclipse, at the left of the offending line, Eclipse can do it for you. Or just press Ctrl+Shift+O.

gd1
  • 11,300
  • 7
  • 49
  • 88
1

Yes, Serializable is an interface. Perhaps you've failed to configure your build path correctly?

user1329572
  • 6,176
  • 5
  • 29
  • 39
  • For an invalid CP there would likely be many more problems O.o –  Jan 03 '13 at 02:27
  • @pst, "*it saying "Serializable cannot be resolved to a type" and offering me to create an inteface called Serializable*"..you would think OP would recognize that Eclipse would give you the option to import the interface as well.. – user1329572 Jan 03 '13 at 02:28
  • You're very trusting of posters :-) –  Jan 03 '13 at 02:29
  • @pst, Yeah..I'll remove my answer. – user1329572 Jan 03 '13 at 02:30
  • No, don't do that. It's not inherently wrong - I up-voted it - and I don't see why this couldn't be the problem, even if I suspect otherwise. –  Jan 03 '13 at 05:14
  • Yes I believe that is it. For some reason when I go to Properties and look at my build path, it says "[unbounded]". – CodyBugstein Jan 04 '13 at 05:41
0

you have just to right click on your project => buildpath => jre => and you specify the right jre and it will gives you the possibility of importing java.io.Serialisable;

Sorinzo
  • 17
  • 2
  • 9