Results 1 to 7 of 7
  1. #1
    russellty is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Exception in thread "main"

    When i run my program, it gives me this error:
    Java Code:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    
    	at main.Start.main(Start.java:31)
    my entire class is here:
    Java Code:
    package main;
    
    import java.awt.*;
    import javax.swing.*;
    
    import java.awt.event.*;
    
    
    @SuppressWarnings("serial")
    public class Start extends JFrame {
    	
    
    	
    	ImageIcon redSquare = new ImageIcon(Start.class.getResource("/main/red.jpg")), 
    			blackSquare = new ImageIcon(Start.class.getResource("/main/black.jpg")), 
    			redChecker = new ImageIcon(Start.class.getResource("/main/redChecker.jpg")), 
    			whiteChecker = new ImageIcon(Start.class.getResource("/main/whiteChecker.jpg")), 
    			redCheckerKing = new ImageIcon(Start.class.getResource("/main/redCheckerKing.jpg")), 
    			whiteCheckerKing = new ImageIcon(Start.class.getResource("/main/whiteCheckerKing.jpg")), 
    			selectedRedChecker =  new ImageIcon(Start.class.getResource("/main/selectedRedChecker.jpg")), 
    			selectedWhiteChecker =  new ImageIcon(Start.class.getResource("/main/selectedWhiteChecker.jpg")), 
    			selectedRedCheckerKing =  new ImageIcon(Start.class.getResource("/main/selectedRedCheckerKing.jpg")),
    			selectedWhiteCheckerKing =  new ImageIcon(Start.class.getResource("/main/selectedWhiteCheckerKing.jpg"));
    	
    	GridBagConstraints c = new GridBagConstraints();
    	GridBagLayout layout = new GridBagLayout();
    	
    	JLabel[][] loacation = new JLabel[8][8];
    	
    	
    	public static void main(String[] args){
    		new Start();
    	}
    	
    	public Start(){
    		
    		for(int counter0 = 0; counter0 <= 7; counter0 ++){
    			for(int counter1 = 0; counter1 <= 7; counter1 ++){
    				if(counter0 % 2 == 0){
    					if(counter1%2 == 0){
    						loacation[counter0][counter1] = new JLabel(new ImageIcon(Start.class.getResource("/main/red.jpg")));
    					}else{
    						loacation[counter0][counter1] = new JLabel(new ImageIcon(Start.class.getResource("/main/black.jpg")));
    					}
    				}else{
    					if(counter1 % 2 == 0){
    						loacation[counter0][counter1] = new JLabel(new ImageIcon(Start.class.getResource("/main/black.jpg")));
    					}else{
    						loacation[counter0][counter1] = new JLabel(new ImageIcon(Start.class.getResource("/main/red.jpg")));
    					}
    				}
    			}
    		}
    		setResizable(false);
    		setBounds(10, 10, 600, 600);
    		
    		setLayout(layout);
    		
    		for (int counter0 = 0; counter0 <= 7; counter0++){
    			c.gridy = counter0;
    			for (int counter1 = 0; counter1 <=7; counter1++){
    				c.gridx = counter1;
    				add(loacation[counter0][counter1], c);
    			}
    		}
    		
    		setTitle("Checkers");
    		
    		setVisible(true);
    		
    		for(int counter = 1; counter <= 7; counter += 2)
    			loacation[0][counter].setIcon(redChecker);
    		
    		for(int counter = 0; counter <= 7; counter += 2)
    			loacation[1][counter].setIcon(redChecker);
    		
    		for(int counter = 1; counter <= 7; counter += 2)
    			loacation[2][counter].setIcon(redChecker);
    		
    		
    		for(int counter = 0; counter <= 7; counter += 2)
    			loacation[5][counter].setIcon(whiteChecker);
    		
    		for(int counter = 1; counter <= 7; counter += 2)
    			loacation[6][counter].setIcon(whiteChecker);
    		
    		for(int counter = 0; counter <= 7; counter += 2)
    			loacation[7][counter].setIcon(whiteChecker);
    		
    		
    		
    		
    		
    		for(int counter = 0; counter <= 7; counter++){
    			for(int counter1 = 0; counter1 <= 7; counter1++){
    				
    				loacation[counter][counter1].addMouseListener(new MouseAdapter() {
    					@Override
    					public void mouseClicked(MouseEvent e) {
    							
    							
    							if(((JLabel) e.getSource()).getIcon() == redChecker){
    								unCheck();
    								((JLabel) e.getSource()).setIcon(selectedRedChecker);
    							}else if(((JLabel) e.getSource()).getIcon() == whiteChecker){
    								unCheck();
    								((JLabel) e.getSource()).setIcon(selectedWhiteChecker);
    							}else if(((JLabel) e.getSource()).getIcon() == redCheckerKing){
    								unCheck();
    								((JLabel) e.getSource()).setIcon(selectedRedCheckerKing);
    							}else if(((JLabel) e.getSource()).getIcon() == whiteCheckerKing){
    								unCheck();
    								((JLabel) e.getSource()).setIcon(selectedWhiteCheckerKing);
    							}else if(((JLabel) e.getSource()).getIcon() == blackSquare ){
    								move(((JLabel) e.getSource()));
    								System.out.println("J");
    							}
    						
    						}
    				});
    				
    			}
    		}
    		
    		
    	}
    	
    	public void move(JLabel destination){
    		
    		System.out.println(getSelectedSquare());
    		
    	}
    	
    	
    	public void unCheck(){
    		
    		for(int counter2 = 0; counter2 <= 7; counter2++){
    			for(int counter3 = 0; counter3 <= 7; counter3++){
    				if(loacation[counter2][counter3].getIcon() == selectedRedChecker){
    					loacation[counter2][counter3].setIcon(redChecker);
    				}else if(loacation[counter2][counter3].getIcon() == selectedWhiteChecker){
    					loacation[counter2][counter3].setIcon(whiteChecker);
    				}else if(loacation[counter2][counter3].getIcon() == selectedRedCheckerKing){
    					loacation[counter2][counter3].setIcon(redCheckerKing);
    				}else if(loacation[counter2][counter3].getIcon() == selectedWhiteCheckerKing){
    					loacation[counter2][counter3].setIcon(whiteCheckerKing);
    				}
    			}
    		}
    		
    	}
    	
    		
    	public JLabel getSelectedSquare(){
    		
    		
    		
    		for(int counter2 = 0; counter2 <= 7; counter2 ++){
    			for(int counter3 = 0; counter3 <= 7; counter3++){
    
    				if(loacation[counter2][counter3].getIcon() == selectedRedChecker ||
    						loacation[counter2][counter3].getIcon() == selectedWhiteChecker ||
    						loacation[counter2][counter3].getIcon() == selectedRedCheckerKing ||
    						loacation[counter2][counter3].getIcon() == selectedWhiteCheckerKing){
    					return loacation[counter2][counter3];
    					
    				}	
    			}
    		}
    		
    		return null;
    		
    	}
    Thanks in advance

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: Exception in thread "main"

    Can you compile the program with the javac command and get the error messages from the compiler?
    The javac compiler gives better error messages than your IDE.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    russellty is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Exception in thread "main"

    How do I use the Javac compiler again? I never really used it...

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: Exception in thread "main"

    Open a command prompt window, change to the directory(use CD command) with the .java source file and enter the javac command:
    javac <SOURCEFILENAME>.java
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    russellty is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Exception in thread "main"

    it just says "javac is not a recognized internal or external command, operable program or batch file

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Exception in thread "main"

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    russellty is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Exception in thread "main"

    wierd. i just tryed running it in eclipse and it worked fine. thanks all!

Similar Threads

  1. Replies: 5
    Last Post: 12-21-2011, 06:44 PM
  2. Replies: 14
    Last Post: 04-08-2011, 06:01 PM
  3. Replies: 5
    Last Post: 06-22-2010, 03:51 PM
  4. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  5. Replies: 6
    Last Post: 07-16-2009, 03:30 PM

Posting Permissions

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