错误:找不到或加载主类 - 新手 [英] Error: Could not find or load main class- Novice

查看:137
本文介绍了错误:找不到或加载主类 - 新手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JAVA的新手。我已经得到这个文件没有找到异常,在文件中存在的文件存在我在路径中指定的那个



最初我有文件没有找到的问题。但是,在执行清理并重新运行后,现在我有一个问题,说


错误:找不到或加载主类main.main




  import Message * 
import java.util。*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
public class main {


public static void main(String [] args){

消息msg =新消息(bob,爱丽丝, 请求, 数据@@@@);
MPasser passerObj = new MPasser(C:\\\Workspace\\config.txt,process1);

}
}

在MPasser构造函数中还有以下有一些相关的代码就是在那里

  public class MPasser(String file_name,String someVariable){
InputStream input;
try {
input = new RandomAccessFile(file_name,r);
} catch(FileNotFoundException e){
e.printStackTrace();
}
Yaml yaml = new Yaml();
映射< String,String> Object =(Map< String,String>)yaml.load(input);
}

对不起,我已经从初始查询进行编辑,以便更清楚


解决方案

在此行上:

  input = RandomAccessFile(C:\Workspace\conf.txt,'r'); 

您需要转义 \ s

  input = RandomAccessFile(C:\\\Workspace\\\conf.txt,'r') ; 


Hi I am a novice in JAVA. I have been getting this file not found exception inspite of the file existing in the very location I have specified in the path which is

Initially I had the issue of file not found. However, after performing a clean and re-run, now I am having an issue which says

Error: Could not find or load main class main.main

import Message.*;
import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
public class main{  


public static void main(String[] args) {

        Message msg=new Message("bob","alice","request","Data@@@@");
        MPasser passerObj=new MPasser("C:\\Workspace\\config.txt","process1");

    }
}

Also in the MPasser Constructor the following piece of relevant code is there

public class MPasser(String file_name,String someVariable){
    InputStream input;
        try {
            input =new RandomAccessFile(file_name,"r");
        } catch (FileNotFoundException e) {
            e.printStackTrace();        
            }
    Yaml yaml = new Yaml();
    Map<String, String> Object = (Map<String, String>) yaml.load(input);
}

Sorry I have made edits from initial query so that it is more clear

解决方案

On this line:

input = RandomAccessFile("C:\Workspace\conf.txt",'r');

You need to escape the \'s

input = RandomAccessFile("C:\\Workspace\\conf.txt",'r');

这篇关于错误:找不到或加载主类 - 新手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆