0

I want to import a class that I made in Eclipse to a project in Android Studio. I have been working on a project in Eclipse which involves a custom class called WordList and I have serialized an instance of this class into a binary file.

Now, I have just started to learn about android programming and I wanted to make an app that uses this file. I want to use something like this to read the WordList object from that file:

ObjectInputStream in = new ObjectInputStream( new FileInputStream(new File( /*file name*/ ))); return (WordList) in.readObject();

But in order to do that, the program of course needs to know about the WordList class, otherwise I'll get a ClassNotFoundException at the cast. What I did first was to create a new WordList class in the Android project that was just an exact copy of the one in the Eclipse project, but then I got that exception:

java.lang.ClassNotFoundException: Didn't find class "package_name.WordList" on path: DexPathList[[zip file "/data/app/my_project_directory-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]].

So apparently, these two identical WordList classes are in fact not identical. Why is it so? Is there a way for me to import the class from the Eclipse project into the Android Studio project, so that I actually can use the very same class? Or is there a way to make the program realize that the file actually contains a serialized WordList object?

  • Was you "*Eclipse*" class programmed by Android specs? What exception did you get? Please post it. – PM 77-1 Apr 10 '15 at 18:55
  • Did your original class set the serialverionUID? If not, you're probably not going to get it to work now. http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it – ControlAltDel Apr 10 '15 at 19:02

1 Answers1

0

Pack the original class and others into a jar file and make it available to the other as a client/lib jar

user1132593
  • 448
  • 1
  • 5
  • 8