How to import .java from another project AND packa

2019-07-15 13:53发布

We're working on a project (Project A) in college that has to extend from a class that is another project (Project B), made years ago. This is working under Eclipse, and developing apps for android, so this is in fact Activities we're talking about.

So far I've tried this:

  • Adding project B on Project A's build path (In the Projects TAB)
  • Importing, with full package name and .java name.

The thing is that every solution I've found is for working with .jar, .class or even .apk files, but I'M NOT working with that, project B is a simple project full of .java files.

To be a little more clear about it, Project A has a class named ClassFromProjectA, and Project B has a class like ClassFromProjectB. ClassFromProjectA is like follows:

public class ClassFromProjectA extends ClassFromProjectB{}

ClassFromProjectB is like follows:

public class ClassFromProjectB extends ListActivity implements OnInitListener, OnGesturePerformedListener {}

The "only" thing ClassFromProjectB is doing is, uppon extending from it, it changes the default layout for a ListView, applies specific navigation options, applies gestures to every activity extending from it, and a couple more tweaks.

If I make this:

public class ClassFromProjectA extends ListActivity{}

Everything works fine with my class, no errors, no warnings, no nothing.

We are ABSOLUTELY sure that ClassFromProjectB is working, it was a previous succesfull college project, and it also has an Example activity within its files to check functionality, and everything works like a charm. That's the thing though, it only works because it is in the same project file. But we CAN'T do that, we have to import and extend, and it isn't workin'.

Please, let me know if you know how to make this work, or point me in the right direction.

2条回答
别忘想泡老子
2楼-- · 2019-07-15 14:11

Try reference projectB in projectA as follows:

  1. Open "Properties" window of projectA
  2. Go to "Android" Tab
  3. Click "Add" button in the "Library"
  4. Select projectB as reference

After this you can import class from projectB.

查看更多
该账号已被封号
3楼-- · 2019-07-15 14:15

What you can do if you have the complete project B that you need to include inside your project (project A).

  1. Make Project B a library in the following manner :
    • Right click the project B in Eclipse, and click on Properties.
    • Select Android then the isLibrary check box. Project B Properties
  2. Once Project B is a library, you have to add the library B (formerly project B) in your project A in the following manner :
    • Right click the project A in Eclipse, and click on Properties.
    • Select Android then click on Add.... Add Library
    • You should see a list with all the library projects inside eclipse on your machine. You should also see Project B. Select it and click OK. Library Selection
    • You should see Project B in the list of libraries. Project B added as Library

Now you should be able to import packages from Project B to project A and use its classes with no problem.

查看更多
登录 后发表回答