"Package .. does not exist" khi chạy chương trình Java bằng cmd

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:
Annotation 2020-09-08 204049
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 ?

Sao bạn không cho nó vào thư mục lib luôn đi. Với lại có vẻ như là lỗi ở đây algs-4.jar

3 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?