简体   繁体   English

如何从另一个模块调用Java类

[英]How to call a class of java from another module

I have a project with the structure 我有一个结构的项目

android/src/com.xy/A.java 安卓/ src目录/ com.xy / A.java

core/src/com.xy/B.java 芯/ SRC / com.xy / B.java

I want to call a method from A.java in B. java. 我想从B.java中的A.java调用方法。 I have searched the internet for solutions i have added the lines 我在互联网上搜索了解决方案,我添加了这些行

implementation project(path: ':core', configuration: 'default')

in android's build.gradle and 在android的build.gradle和

implementation project(path: ':android', configuration: 'default')

in core's build.gradle file. 在核心的build.gradle文件中。

It builds with success but i cannot call the class from B. java 它构建成功,但我无法从B. java中调用该类。

Import the statement 导入语句

import android.src.com.x.y.A.*;

Then make an object of A.java as follows: 然后按如下所示创建A.java的对象:

A a = new A();

Then use it's methods in class B wherever you want. 然后在任何地方使用B类中的方法。

a.pqr()

For further guidance and understanding the concepts, go through official documentation. 要获得进一步的指导和理解这些概念,请查阅官方文档。 https://docs.oracle.com/javase/tutorial/ https://docs.oracle.com/javase/tutorial/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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