简体   繁体   中英

How to call a class of java from another module

I have a project with the structure

android/src/com.xy/A.java

core/src/com.xy/B.java

I want to call a method from A.java in B. 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

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

in core's build.gradle file.

It builds with success but i cannot call the class from B. java

Import the statement

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

Then make an object of A.java as follows:

A a = new A();

Then use it's methods in class B wherever you want.

a.pqr()

For further guidance and understanding the concepts, go through official documentation. https://docs.oracle.com/javase/tutorial/

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