简体   繁体   English

添加CLASSPATH后,无法找到或加载主类

[英]Could not find or load main class, after adding CLASSPATH

Hi I'm doing Princeton Algorithms assignment when I ran into the following problem. 嗨,当我遇到以下问题时,我正在做普林斯顿算法分配。

Both BruteCollinearPoints.java and input8.txt are in C:\\Users\\Jen\\Desktop\\princeton-algorithms\\collinear . BruteCollinearPoints.java和input8.txt都位于C:\\Users\\Jen\\Desktop\\princeton-algorithms\\collinear

I have been trying to run java-algs4 BruteCollinearPoints input8.txt from the aforementioned path to no avail. 我一直在尝试从上述路径运行java-algs4 BruteCollinearPoints input8.txt无效。 I kept getting Error: Could not find or load main class BruteCollinearPoints . 我不断收到Error: Could not find or load main class BruteCollinearPoints

Below is my classpath: 下面是我的类路径:

CLASSPATH: C:\\Users\\Jen\\algs4\\algs4.jar;

First of all you need to make sure that your BruteCollinearPoints class has main method. 首先,您需要确保您的BruteCollinearPoints类具有main方法。 It could look like the following 它可能如下所示

import java.util.ArrayList;
import java.util.Arrays;
import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.StdDraw;
import edu.princeton.cs.algs4.StdOut;

public class BruteCollinearPoints {

    // implementation of other methods

    public static void main(String[] args) {
        // read the n points from a file
        In in = new In(args[0]);
        int n = in.readInt();
        Point[] points = new Point[n];
        for (int i = 0; i < n; i++) {
            int x = in.readInt();
            int y = in.readInt();
            points[i] = new Point(x, y);
        }

//         draw the points
        StdDraw.setXscale(0, 32768);
        StdDraw.setYscale(0, 32768);
        StdDraw.setPenColor(StdDraw.RED);
        StdDraw.setPenRadius(0.01);
        for (Point p : points) {
            p.draw();

        }
        StdDraw.show();

        // print and draw the line segments
        BruteCollinearPoints collinear = new BruteCollinearPoints(points);
        for (LineSegment segment : collinear.segments()) {
            StdOut.println(segment);
            segment.draw();
        }
        StdDraw.show();
    }
}

For more details please refer assignment's page ( link ). 有关更多详细信息,请参阅作业页面( 链接 )。

Also, CLASSPATH environment variable should include C:\\Users\\Jen\\Desktop\\princeton-algorithms\\collinear directory as well as algs4.jar archive. 另外, CLASSPATH环境变量应包括C:\\Users\\Jen\\Desktop\\princeton-algorithms\\collinear目录以及algs4.jar存档。

CLASSPATH: C:\\Users\\Jen\\algs4\\algs4.jar;C:\\Users\\Jen\\Desktop\\princeton-algorithms\\collinear

Execute javac-algs4 *.java from C:\\Users\\Jen\\Desktop\\princeton-algorithms\\collinear directory to compile sources to binaries. C:\\Users\\Jen\\Desktop\\princeton-algorithms\\collinear目录执行javac-algs4 *.java ,将源代码编译为二进制文件。

Execute java-algs4 BruteCollinearPoints input8.txt to run main method of BruteCollinearPoints class. 执行java-algs4 BruteCollinearPoints input8.txt以运行BruteCollinearPoints类的main方法。

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

相关问题 错误:添加依赖项后(Maven)找不到或加载主类 - Error: Could not find or load main class after adding dependency (maven) 更改CLASSPATH后,Java无法“找不到或加载主类硬件” - Java Cannot “Could not find or load main class HW” after I change CLASSPATH Java“无法找到或加载主类”,类路径错误 - Java “could not find or load main class” with classpath error 构建后找不到或加载主类 - Could not find or load the main class after build 添加更多程序包后,Visual Studio代码无法找到或加载主类 - Visual Studio code could not find or load main class after adding more packages 在将提供的 spark.jar 依赖项添加到 gradle 构建后得到“找不到或加载主类” - getting 'Could not find or load main class' after adding provided spark .jar dependencies to gradle build Java类存在于类路径中,但启动失败并出现错误:找不到或加载主类 - Java class is present in classpath but startup fails with Error: Could not find or load main class 添加包语句时找不到或加载主类 - Could not find or load main class when adding package statement 添加 maven 依赖项时无法找到或加载主类错误 - Could not find or load main class error when adding maven dependency 添加依赖项时:“无法找到或加载主类” - When adding Dependency: “could not find or load Main Class”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM