REALLY annoying java error!!!

Discussion in 'Programming' started by whiteblue1942, Oct 24, 2009.

  1. #1
    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):
     
    whiteblue1942, Oct 24, 2009 IP
  2. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #2
    What errors are you getting ?
     
    it career, Oct 28, 2009 IP
  3. gacba

    gacba Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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. :D
     
    gacba, Oct 28, 2009 IP
  4. sn3twork

    sn3twork Active Member

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #4
    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..
     
    sn3twork, Oct 29, 2009 IP
  5. be@stie

    be@stie Member

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    Trying to compile a class with code inside and without any methods is a nice point :D. Have you tried to read any Java Programming books? No offense, man. I may suggest some.
     
    be@stie, Oct 30, 2009 IP
  6. sn3twork

    sn3twork Active Member

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #6
    lol .
     
    sn3twork, Oct 31, 2009 IP