简体   繁体   中英

Use an Eclipse class in android studio?

My problem is quite simple, I've created a class in an eclipse project, in the app, I save multiple instances of the class in files to open later. Now, I've copied the class to Android Studio and saved an instance of the class in a file that I later try to open with the Eclipse app, but , I got a ClassNotFoundException, claiming that the Eclipse programm cloud not recognize the (package of android app).classname Class.

How can I do this correctly?

This is a little advice for you. I was faced the same problem in last few year. I think there is no way to solve this problem. I created new project in eclipse and copy the code.

You need to add the correct import to access the class, for example:

com.jorgesys.myapp
             - MainActivity.java

com.jorgesys.myapp.views
                   - OtherClass.java

to access OtherClass.java from MainActivity.java , then add the import:

import com.jorgesys.myapp.views.OtherClass;

After a while, what I finally did was create another project on Eclipse with all the common classes, export it as a .jar file and add it as a library for both PC and Android project. It worked, kind of, because it seem that android does not write objects into files the same way that PC jvm does, but, I managed to use Gson on both applications to store the object I needed in a JSON String format and then re-open it on desktop.

A bit long, what was the cleaner solution I found.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM