[英]How to use external libraries in the Eclipse (Java) and Processing for Arduino
[英]Regarding how to use external libraries in eclipse (java)
我是 Java 的完全初学者,使用 eclipse 甚至在安装了那些正确的外部库之后,(我将它们安装到我的构建路径中,它们进入了我的引用库部分)这将使我的工作变得容易我不能将它们用于一些理由。
import acm.*;
我用它来导入这个库的所有类,当我试图在我的程序中使用这些类时,由于某种原因它不起作用。如果我尝试使用 print() 方法,它会给我以下错误这个库的 class IOconsole 的一个方法。
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method print(String) is undefined for the type ShortPrint
at ShortPrint.main(ShortPrint.java:5)
我不知道我是否错过了任何步骤,但我很确定我已经正确安装了这些库,只是无法使用它们。
编辑 1:这是我的程序。
import acm.*;
public class ShortPrint {
public static void main(String []args) {
print ("hello");
}
}
我相信您应该将导入更改为:
import static acm.IOConsole.*
因为IOConsole
中的print()
方法似乎是static
。
你需要有一个 object 的 ShortPrint,像这样
ShortPrnt sp = new ShortPrint();
sp.print("Hello");
我猜你正试图这样调用print
:
ShortPrint.print("Hello");
这只会工作是print
是 ShortPrint 的ShortPrint
另一种可能性是您没有从IOConsole
继承ShortPrint
,这IOConsole.print
无法从ShortPrint
访问
更新:在 OP 添加使用代码后,建议添加导入
import acm.io.*;
因为IOConsole
class 驻留在acm.io
package 中。然后将调用更改为
IOConsole cons = new IOConsole();
cons.print("hello");
因为print()
不是 IOConsole 的IOConsole
成员
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.