Results 1 to 2 of 2
  1. #1
    loosemember is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default What is wrong with my code?

    Java Code:
    import java.io.*;
    
    public class ReadBds {
    	public static void main( String [] args ) {
    		char [][] bd = new char [8][8];
    		if (args.length==0)
    			args = "board01.txt board02.txt board03.txt".split(" ");
    		for (String fn : args)
    		{
    			try{
    				BufferedReader bf = new BufferedReader(
    						new FileReader(fn));
    				// Read board from file
    				for (int i=0;i<8;i++)
    				{
    					String s = bf.readLine();
    					for (int j=0;j<8;j++)
    						bd[i][j] = s.charAt(j);
    				}
                                               
    				
    				for (int i=0;i<8;i++)
    					for (int j=0;j<8;j++)
    						if (bd[i][j]=='X_X_X_X_' || bd[i][j]=='_X_X_X_X')
    				System.out.printf("Is an empty line %s: %d\n",
    						fn,i);
    			}
    			catch (IOException e) {
    				System.out.printf("Problem with file: %s",fn);
    			} 
    		}
    	}
    }
    I get this error

    Java Code:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    	Invalid character constant
    
    	at ReadBds.main(ReadBds.java:24)
    on the line

    Java Code:
    if (bd[i][j]=='X_X_X_X_' || bd[i][j]=='_X_X_X_X')
    cheers

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    In Java Strings require double quotes " not single quotes '.

    Also you're not going to want to use == to compare Strings but rather the equals method. Do you know why this is so?

Similar Threads

  1. What is wrong with this code?
    By Mythreadings in forum New To Java
    Replies: 38
    Last Post: 11-19-2010, 01:43 AM
  2. what is wrong with my code???
    By EBBOOO in forum New To Java
    Replies: 30
    Last Post: 07-27-2010, 10:59 PM
  3. what's wrong with my code? please help me...
    By lovely23 in forum Java Applets
    Replies: 2
    Last Post: 03-01-2009, 02:33 PM
  4. What's wrong with this code?
    By Doctor Cactus in forum New To Java
    Replies: 4
    Last Post: 11-29-2008, 06:44 PM
  5. what is wrong with this code
    By masaka in forum New To Java
    Replies: 5
    Last Post: 04-16-2008, 09:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •