M viết chương trình sử dụng thư viện bên ngoài dùng NetBeans IDE khi chạy bằng cmd bị lỗi.
Tạo class trong package mặc định:
Code của UFClient.java
package dsasample;
import edu.princeton.cs.algs4.*;
public class UFClient {
public static void main(String[] args)
{
int N = StdIn.readInt();
UF uf = new UF(N);
while (!StdIn.isEmpty())
{
int p = StdIn.readInt();
int q = StdIn.readInt();
if (!uf.connected(p, q))
{
uf.union(p, q);
StdOut.println(p + " " + q);
}
}
}
}
Chạy trên cmd bằng lệnh:
javac -cp D:\coursera\algs-4.jar;. UFClient.java
thì bị lỗi sau:
D:\Netbean_Proj\DSASample\src\dsasample>javac -cp D:\coursera\algs-4.jar;. UFClient.java
UFClient.java:7: error: package edu.princeton.cs.algs4 does not exist
import edu.princeton.cs.algs4.*;
^
UFClient.java:15: error: cannot find symbol
int N = StdIn.readInt();
^
symbol: variable StdIn
location: class UFClient
UFClient.java:16: error: cannot find symbol
UF uf = new UF(N);
^
symbol: class UF
location: class UFClient
UFClient.java:16: error: cannot find symbol
UF uf = new UF(N);
^
symbol: class UF
location: class UFClient
UFClient.java:17: error: cannot find symbol
while (!StdIn.isEmpty())
^
symbol: variable StdIn
location: class UFClient
UFClient.java:19: error: cannot find symbol
int p = StdIn.readInt();
^
symbol: variable StdIn
location: class UFClient
UFClient.java:20: error: cannot find symbol
int q = StdIn.readInt();
^
symbol: variable StdIn
location: class UFClient
UFClient.java:24: error: cannot find symbol
StdOut.println(p + " " + q);
^
symbol: variable StdOut
location: class UFClient
8 errors
Ít khi compile bằng cmd không biết lỗi gì và sửa ntn ?