首页 > 解决方案 > 错误:无法找到或加载主类 MyCSVParser

问题描述

我有一个从 .java 编译的 .class

package csvExam.MyCSVParser;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class MyCSVParser {


    public static void main(String[] args){
        String csvFile = "/Users/dbaug/Desktop/idestuff/csvExam/testme.csv";
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";

        if(csvFile==null){

            System.out.println("no CSV File found, try again.");

        }else{

            try {

                br = new BufferedReader(new FileReader(csvFile));
                while ((line = br.readLine()) != null) {
                    String[] mainLine = line.split(cvsSplitBy);

                    System.out.println("am I reading anything");

                }

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (br != null) {
                    try {
                        br.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

我能够使用 javac MyCSVParser.java 进行编译,并且我收到了一个 MyCSVParser.class 这两个文件都位于“C:\Users\dbaug\Desktop\idestuff\csvExam”中

我的 %PATH% 是:

C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\ Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\ System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1. 0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86) \Intel\Intel(R) 管理引擎组件\IPT;C:\Program Files\Intel\Intel(R) 管理引擎组件\IPT;C:\WINDOWS\System32\OpenSSH\;C:\WINDOWS\system32\config\ systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\ WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Java\jdk1.8.0_191\bin;C:\Program Files\dotnet\;C:\Users\ dbaug\AppData\Local\Microsoft\WindowsApps;C:\Users\dbaug\AppData\Local\GitHubDesktop\bin;C:\Program Files\Java\jdk1.8.0_191\bin;\Program Files\Java\jdk1.8.0_191\bin;\Program Files\Java\jdk1.8.0_191\bin;

在哪里可以看到“;C:\Program Files\Java\jdk1.8.0_191\bin;” 在底部。

在环境变量中,我将变量路径设置为“C:\Program Files\Java\jdk1.8.0_191\bin”

以下是我遇到的所有输入和结果。

Microsoft Windows [版本 10.0.17763.316] (c) 2018 Microsoft Corporation。版权所有。

C:\用户\dbaug>cd c:\

c:>java -classpath C:\Users\dbaug\Desktop\idestuff\csvExam MyCSVParser 错误:无法找到或加载主类 MyCSVParser

c:>java -cp C:\Users\dbaug\Desktop\idestuff\csvExam MyCSVParser 错误:无法找到或加载主类 MyCSVParser

c:>cd C:\Users\dbaug\Desktop\idestuff\csvExam

C:\Users\dbaug\Desktop\idestuff\csvExam>java MyCSVParser 错误:无法找到或加载主类 MyCSVParser

C:\Users\dbaug\Desktop\idestuff\csvExam>cd C:\Users\dbaug\Desktop\idestuff

C:\Users\dbaug\Desktop\idestuff>java csvExam.MyCSVParser 错误:无法找到或加载主类 csvExam.MyCSVParser

C:\Users\dbaug\Desktop\idestuff>

除了尝试让 .class 通过终端运行之外,我并没有尝试做任何特别的事情,因为这是我从 IDE 验证我的程序工作的下一步。但是,我整天都在为自己可能做错的事情感到难过,我只是不确定。我运行 Windows 10,尝试使用 Java JDK jdk1.8.0_191,我从 oracle java 网站下载。

标签: javaterminalcompilation

解决方案


你好我不知道我做错了什么,但我改变了包 csvExam; 我现在 cd 到目录并且可以“java csvExam.MyCSVParser”


推荐阅读