Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-10-2005, 01:19 PM   #1
Registered: Aug 2004
Posts: 51

Rep: Reputation: 15
Angry Newbie question on java

Hi all,
The following code is compiling but giving error in case of executing.


public class File1
public static void main (String[] args)
String file_name;
BufferedReader br = new BufferedReader(new InputStreamReader(;
System.out.print("Enter file name eg: (test.txt) ");
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 =;
String s = new String(buff);
catch(FileNotFoundException e)
System.out.println("File not found.");
catch(IOException e)

} //main

The runtime error i am getting is

Exception in thread "main" java.lang.NoClassDefFoundError: File1

Plz clarigy my doubt

wating for ur replies,
Old 05-10-2005, 01:37 PM   #2
LQ Newbie
Registered: Dec 2004
Posts: 21

Rep: Reputation: 15
To compile you would use: javac

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.

Old 05-10-2005, 03:35 PM   #3
Senior Member
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
and next time you post code, please put it between [ code ] and [/ code ] tags
Old 05-10-2005, 10:47 PM   #4
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 32
Komakino, how do get the tags to show up in your post without them being processed as the actual tags?
Old 05-11-2005, 04:58 AM   #5
Registered: Dec 2003
Location: Bangkok- Thailand
Distribution: Mandriva 10.0,Fedora Core 4
Posts: 79

Rep: Reputation: 15
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 !

Last edited by hus; 05-11-2005 at 02:06 PM.
Old 05-11-2005, 05:40 AM   #6
Registered: Oct 2003
Distribution: Slackware
Posts: 101

Rep: Reputation: 15
Originally posted by johnMG
Komakino, how do get the tags to show up in your post without them being processed as the actual tags?
He added spaces before and after the brackets.
Old 05-12-2005, 01:47 PM   #7
Registered: Apr 2005
Location: Susex, England.
Distribution: Slackware 10.1, Devil Linux
Posts: 49

Rep: Reputation: 15

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.

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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
java newbie question method headers and if statements dflan98783 Programming 6 02-22-2007 12:18 AM
A very basic newbie question on Java lmellen Programming 5 07-19-2004 04:59 PM
newbie java question lmellen Programming 6 06-30-2004 05:34 PM
Java Newbie Question patpawlowski Programming 6 02-27-2004 05:25 PM
Newbie question about executing java command oldoldcat Linux - General 4 01-30-2004 02:15 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration