1

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

animuson
  • 53,861
  • 28
  • 137
  • 147
ExceptionHandler
  • 213
  • 1
  • 8
  • 24
  • 1
    why does your constructor has a `Class` keyword associated with it – RanRag Jan 23 '12 at 01:26
  • 1
    You should respect the case: `public` not `Public` and `class` if that's the class definition (although you're talking about a constructor here). Shouldn't that be `"r"` instead of `'r'` too? (As others have said, you're also missing `new`.) – Bruno Jan 23 '12 at 01:30
  • @Bruno "r" is taken care off, but the issue persists. The point to be noted here is the fact that, it shows error in 11th line in the main() function where there is actually no line of code as such. I presume you are talking about the new for the `new RandomAccessFile(file_name,"r");` That is also not helping – ExceptionHandler Jan 23 '12 at 01:36
  • 1
    The fact that this 11th line (where the exception is thrown) is somewhere where there is no code could indicate that you're not actually running a version of the code compiled from your latest source file. Hard to say, but since you seem to indicate you're a novice, could you double check? – Bruno Jan 23 '12 at 01:39
  • @Bruno I did clean and run the file. Now I have a new error. The file not found exception is gone but a new exception Error: Could not find or load main class main – ExceptionHandler Jan 23 '12 at 01:44
  • 1
    Just a suggestion you should not name your class `public class main` main.Always use names which signify the purpose of your code. – RanRag Jan 23 '12 at 01:45
  • @RanRag do you think it could be a naming issue? I tried changing the name into something else and still the error persists – ExceptionHandler Jan 23 '12 at 01:47
  • No its not a naming issue. I just gave a naming convention related suggestion. – RanRag Jan 23 '12 at 01:48
  • @RanRag yeah I do understand that. Thanks for the constructive suggestion :) – ExceptionHandler Jan 23 '12 at 01:49
  • I believe your `message` and `main` class are not in the same folder.Am i right. – RanRag Jan 23 '12 at 01:50
  • @RanRag yes. They are two different packages under the same src folder – ExceptionHandler Jan 23 '12 at 01:54
  • have you compiled your message and MPasser class. – RanRag Jan 23 '12 at 02:03
  • @RanRag Yes I have. There is no issue with that so far – ExceptionHandler Jan 23 '12 at 02:17

4 Answers4

2

On this line:

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

You need to escape the \'s

input = RandomAccessFile("C:\\Workspace\\conf.txt",'r');
seth.miller
  • 1,988
  • 17
  • 23
1
 "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?

James M
  • 18,506
  • 3
  • 48
  • 56
1

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

NiranjanBhat
  • 1,812
  • 13
  • 17
0

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.

RanRag
  • 48,359
  • 38
  • 114
  • 167