| Sajha.com Archives | ![]() |
| Username | Post |
| Biruwa | Posted
on 31-Mar-03 07:37 PM
I am having problem running my java program. I used javac to complile my file and it compiles and creates the class file but when I try to run this by giving the command java test (test is the class file name) it says "Exception in thread "main" java.lang.NoClassDefFoundError: test" I have tried reinstalling the java and still it doesn't work. I don't think it is a path problem since I set the path correctly otherwise javac also wouldn't have worked. I did set the path to c:\j2sdk1.4.1_02\bin. I also set the class path by set classpath=c:\j2sdk1.4.1_02\jre\lib\rt.jar. Suggestions please! |
| dawn | Posted
on 01-Apr-03 06:29 AM
Most of the time java.lang.NoClassDefFoundError leads either to misspelt class or incorrect classpath. Thus check the name of your class ( it is case sensitive) try to add current directory at the end of the classpath i.e CLASSPATH=c:\j2sdk1.4.1_02\jre\lib\rt.jar;. ( On windows Platform) or CLASSPATH=c:\j2sdk1.4.1_02\jre\lib\rt.jar:. ( on Unix like environment) Hopefully it will solve your problem dawn |
| Biruwa | Posted
on 01-Apr-03 07:35 PM
Thanks dawn, Your solution worked. I had not put ";." to my classpath. Infact some months ago when i didn't use ";." at the end of the classpath I used to work. Have they changed anything? Thanks again!! |
| dawn | Posted
on 02-Apr-03 06:07 AM
Nothing has been changed as far as CLASSPATH concept is concerned.Please let me know if you find something else. |
| Biruwa | Posted
on 03-Apr-03 12:57 PM
I want to use the following program to count the number of lines in a file. I am getting error in textreader (cannot resolve symbol). What is wrong with this implementation? I am getting errors for both the textreader lines. I found the program at http://math.hws.edu/javanotes/c10/ex-10-2-answer.html. Please help! import java.io.*; public class LineCounts { public static void main(String[] args) { if (args.length == 0) { // This program must have at least one command-line // argument to work with. System.out.println("Usage: java LineCounts return; } for (int i = 0; i < args.length; i++) { System.out.print(args + ": "); countLines(args); } } // end main() static void countLines(String fileName) { TextReader in; // A stream for reading from the file. int lineCount; // Number of lines in the file. try { in = new TextReader( new FileInputStream(fileName) ); } catch (Exception e) { System.out.println("Error. Can't open file."); return; } lineCount = 0; try { while (in.peek() != '\0') { // Read the next line and count it. in.getln(); lineCount++; } } catch (Exception e) { System.out.println("Error. Problem with reading from file."); return; } System.out.println(lineCount); } // end countLines() } // end class LineCounts |
| hard_ | Posted
on 03-Apr-03 01:22 PM
Biruwa, The reason for that error is that's a custom class created by that person. If you want to use that program you will have to get that class from that person as well, put it in classpath and compile again. Or else, if all you need is just to read the number of lines in a file, here's a simpler version: import java.io.*; public class CountLines{ public static void main(String[] args){ try{ File f = new File(args[0]); BufferedReader bfr = new BufferedReader(new InputStreamReader(new FileInputStream(f))); int i=0; while(bfr.readLine()!=null) i+=1; System.out.println(i); }catch(Exception ex){ex.printStackTrace();} } } the first argument to the program will the name of the file for which you want to count the lines. |
| dawn | Posted
on 03-Apr-03 01:29 PM
Because- you have imported java.io and TexReader class is not part of that package. Thus All you need to do : Get TextReader class( write your own or download from that site if it is availbale) and compile your whole package and rock and roll :) |
| Biruwa | Posted
on 07-Apr-03 09:53 AM
>javac LineCounts.java LineCounts.java:37: cannot resolve symbol symbol : class FileInputStream location: class LineCounts in = new TextReader(new FileInputStream(fileName)); ^ 1 error It seems the error is in FileInputStream. What's the error now?? |
| Biruwa | Posted
on 07-Apr-03 10:00 AM
I have solved the problem myself. Sorry for inconvenience. |