Error: Could not find or load main class- Novice

六月ゝ 毕业季﹏ 提交于 2019-12-20 03:55:52

问题


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


回答1:


On this line:

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

You need to escape the \'s

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



回答2:


 "C:\Workspace\conf.txt"

Those are escape sequences. You probably meant:

 "C:\\Workspace\\conf.txt"

You also appear to call it config.txt in one snippet and conf.txt in the other?




回答3:


Make sure the java process has permissions to read the file.




回答4:


You have to escape the backslash.

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

and also

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

and why you have two different filename conf.txt and config.txt.



来源:https://stackoverflow.com/questions/8966266/error-could-not-find-or-load-main-class-novice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!