I will pay someone to solve this error for me. It is really annoying, i shouldnt be getting it! import java.io.*; import java.util.*; public class Materials { File file = new File("material.txt"); String[][] items = new String[100][8]; int r = 0; try{ BufferedReader reader = new BufferedReader(new FileReader(file)); String line = null; while((line=reader.readLine()) != null){ StringTokenizer st = new StringTokenizer(line,","); while(st.hasMoreTokens()){ for(int c = 0; c < 8; c++){ items[r][c]=st.nextToken(); System.out.print(items[r][c]); } r++; System.out.println(); } } } catch(Exception e){ System.out.println(e); } } Code (markup):
Well, without the actual error you're getting, I can take a few guesses at potential problems: 1) Your Java code as posted won't compile...you're missing a "main" method. 2) When you're reading in the lines from the file, if there are more than 100 lines in the file your "items" buffer will overflow. 3) You're not handling the exceptions gracefully and closing the file after one. Just a few thoughts...post the real error and I can be more specific.
Yea I PM'ed him with some fixes but I don't think he ever actually read it. The first mistake he was making was not putting code in a method at all.. so I don't think we can really fault him for not handling exceptions correctly as most beginners with java simply just throw them instead of using a try catch... as for closing his files yea he should have done that..
Trying to compile a class with code inside and without any methods is a nice point . Have you tried to read any Java Programming books? No offense, man. I may suggest some.