如何导入.java从另一个项目和包在Android [英] How to import .java from another project AND package in android

查看:189
本文介绍了如何导入.java从另一个项目和包在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在大学里开展一个项目(Project A),这个项目必须从几年前开始的另一个项目(Project B)的课程延伸出来。
这是在Eclipse下工作,开发Android应用程序,所以这实际上是我们正在讨论的活动。

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:


  • 在Project A的构建路径上添加项目B(在Projects TAB中)

  • 导入,具有完整的包名称和.java名称。

事实是,我找到的每个解决方案都是使用.jar。类或甚至.apk文件,但我不是这样工作,项目B是一个简单的项目,充满了.java文件。

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.

要更清楚一点它,项目A有一个名为ClassFromProjectA的类,项目B有类似 ClassFromProjectB 的类。 ClassFromProjectA 如下:

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如下:

ClassFromProjectB is like follows:

public class ClassFromProjectB extends ListActivity implements OnInitListener, OnGesturePerformedListener {}

ClassFromProjectB正在做的事情是,从它开始,它改变了ListView的默认布局,应用了特定的导航选项,将手势应用到从其延伸的每个活动中,还有几个调整。

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.

如果我这样做:

public class ClassFromProjectA extends ListActivity{}

一切都适用于我的课程,没有错误,没有警告,没有任何东西。

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

我们绝对确定, ClassFromProjectB 正在工作,这是一个以前的成功的大学项目,它还有一个示例活动在其文件中检查功能,一切都像一个魅力。这是事情,它只是因为它在同一个项目文件中起作用。但是我们不能这样做,我们必须导入和扩展,而不是工作。

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.

推荐答案

如果您需要完整的项目B,您可以做什么包括在您的项目(项目A)中。

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


  1. 使项目B以下列方式创建图书馆:


    • 右键单击Eclipse中的项目B ,然后单击属性

    • 选择 Android ,然后是 isLibrary 复选框。

  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.

  • 右键单击Eclipse中的项目A ,然后单击属性

  • 选择 Android 点击添加...

  • 你应该看到一个列表,全部图书馆在您的机器上的eclipse项目中。您还应该看到项目B 。选择它,然后单击确定

  • 您应该看到项目B在图书馆清单

  • Right click the project A in Eclipse, and click on Properties.
  • Select Android then click on Add....
  • 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.
  • You should see Project B in the list of libraries.

现在您应该能够将项目B中的软件包导入到项目A,并使用其类没有问题。

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

这篇关于如何导入.java从另一个项目和包在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆