![](/img/trans.png)
[英]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.