简体   繁体   English

访问另一个类的公共方法的问题

[英]Problems accessing public method of another class

I currently use two classes, ircBot(extends pircbot ) and ircRobotti(extends Robotti) . 我目前使用两个类, ircBot(extends pircbot )和ircRobotti(extends Robotti)

I'm trying to compile the class files on a shell but i'm getting an error: 我正在尝试在shell上编译类文件但是我收到一个错误:

./ircBot.java:26: cannot find symbol symbol : method lisaaJonoon(int) location: class Robotti annaRobo().lisaaJonoon(suunta); ./ircBot.java:26:找不到符号符号:方法lisaaJonoon(int)位置:class Robotti annaRobo()。lisaaJonoon(suunta);

lisaaJonoon() is defined in ircRobotti and it's public. lisaaJonoon()ircRobotti定义并且是公开的。

Any ideas what might cause the error? 什么可能导致错误的想法?

lisaaJonoon(int)有一个int类型的参数,它与lisaaJonoon()不同。

A public method from one class will be accessible in other class if you make sure that 如果您确定,可以在其他类中访问来自一个类的公共方法

1: Both classes are in same package. 1:两个类都在同一个包中。 If they are in different packages then you need to import the class whose method you are calling. 如果它们位于不同的包中,那么您需要导入要调用其方法的类。

2: The class whose method is being called, should also be compiled. 2:还应编译其方法被调用的类。

3: Make sure, method signatures are same as in called method. 3:确保方法签名与被调用方法相同。 (ie the number of arguments an d their type) (即参数的数量和类型)

Just a guess but as you are compiling on a shell you're probably not setting the classpath correctly. 只是一个猜测,但是当你在shell上编译时,你可能没有正确设置类路径。 How are you invoking javac? 你是如何调用javac的?

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

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