且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误:找不到或加载主类 - 新手

更新时间:2022-10-22 17:05:01

在此行上:

  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');