Newbie question on java
Hi all,
The following code is compiling but giving error in case of executing. <code> import java.io.*; public class File1 { public static void main (String[] args) { String file_name; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter file name eg: (test.txt) "); try { file_name = br.readLine(); // getting file name from user InputStream fileIn = new FileInputStream(file_name); File ff = new File(file_name); long lon_size = ff.length(); //getiing the length of the file int buff_size = (int)lon_size; System.out.println("Size of File " + lon_size); byte buff[] = new byte[buff_size]; int i = fileIn.read(buff); String s = new String(buff); System.out.println(s); } catch(FileNotFoundException e) { System.out.println("File not found."); } catch(IOException e) { e.printStackTrace(); } } //main }//class </code> The runtime error i am getting is Exception in thread "main" java.lang.NoClassDefFoundError: File1 Plz clarigy my doubt wating for ur replies, C00000000000000L |
To compile you would use: javac File1.java
To run it, you would type: java File1 If you still get a NoClassDefFoundError, try setting the classpath: type "export CLASSPATH=<directory of File1.class file>" and then running "java File1" again. LinuxDave |
and next time you post code, please put it between [ code ] and [/ code ] tags
|
Komakino, how do get the tags to show up in your post without them being processed as the actual tags?
|
I guess you use JCreator.
It impossible that JVM can't find main method Try to set Build >Runtime Configuration > edit default > you will see main text field and put the class that the main main method exist to it >OK it should work ! |
Quote:
|
Coolguy_iiit!
Sorry, this has nothing to do with this thread but I need some way of contacting you! I can't send you PM's and you've disabled sending e-mails via this site. :mad: If you're still interested in the project I told you about some time ago, I wanted to let you know that I've started to put my site together. It's nothing fancy yet, I'm more interested in getting the content together first, then I'll worry about the look. However, I would like you to have a look at it and tell me what you think. The code itself is not ready yet, I've hit some bugs that I need to track down before I can release anything but I'm working on it daily so it'll be READY REAL SOON (TM). I also see you've been putting up posts relating to web design, that's good. I'm also starting to experiment with this (though at the moment the project has taken priority) so I think we can really help each other out on this. My site and e-mail addresses are available below, get in touch if you're interested. |
All times are GMT -5. The time now is 09:45 AM. |