Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: ERROR : "CLASS NAME IS ABSTRACT CANNOT BE INSTATIATED"

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ERROR : "CLASS NAME IS ABSTRACT CANNOT BE INSTATIATED"

    GUYS WHAT IS THE COURSE OF THIS ERROR



    import java.awt.event.*;
    import javax.swing.*;
    import tict.TicTGui;
     
    //import tict.TicTGui;
     
      abstract class TicT implements ActionListener
    {
    	/*	Variables*/
        private javax.swing.JButton button1;
        private javax.swing.JButton button2;
        private javax.swing.JButton button3;
        private javax.swing.JButton button4;
        private javax.swing.JButton button5;
        private javax.swing.JButton button6;
        private javax.swing.JButton button7;
        private javax.swing.JButton button8;
        private javax.swing.JButton button9;
        private javax.swing.JFrame jFrame1;
     
        private String letter = "";
        public static int count = 0;
     
        /*Make The Window Visible*/
         public void run()
                {
                    new TicTGui().setVisible(true);
                    setCount(1);
     
                }
     
     
     
        private void setCount(int i)
        {
            throw new UnsupportedOperationException("Not yet implemented");
        }
     
    	/*Calculate Who's Turn It Is*/
        public int  WhoToPlay()
        {
     
            if(count == 1 || count == 3 || count == 5 || count == 7 || count == 9|| count == 11)
            {
                letter = "X";
     
            } else
            		if(count == 2 || count == 4 || count == 6 || count == 8 || count == 10)
            {
                letter = "O";
            }
    		return count;
        }
     
    	/*checking who plays*/
       	public void MakeYourMove(int count)
    	{
    		/*int me=0;
    		int you=0;
    		if(count%2==2)
    		{
    			count=me;
    		}
    		else
    		{
    		 	count=you;
    		}*/
     
     
        	for(int i=0;i<9;i++)
        	{
     
        		if(count==1)
        		{
    			 String input = JOptionPane.showInputDialog("welcome  you will take X and computer wiil take O \n Please ENTER number you want to play ");
            		 int pawn = Integer.parseInt(input);
                    //set letter  to choosen buttons
                    switch (input)
                    {
                        case "1":
                            button1.setText("X");
                            button1.setEnabled(false);
                            break;
                        case "2":
                            button2.setText("X");
                            button2.setEnabled(false);
                            break;
                        case "3":
                            button3.setText("X");
                            button3.setEnabled(false);
                            break;
                        case "4":
                            button4.setText("X");
                            button4.setEnabled(false);
                            break;
                        case "5":
                            button2.setText(letter);
                            button5.setEnabled(false);
                            break;
                        case "6":
                            button6.setText("X");
                            button6.setEnabled(false);
                            break;
                        case "7":
                            button7.setText("X");
                            button7.setEnabled(false);
                            break;
                        case "8":
                            button8.setText("X");
                            button8.setEnabled(false);
                            break;
                        case "9":
                            button9.setText(letter);
                            button9.setEnabled(false);
                            break;
                        default:
                            JOptionPane.showInputDialog("Sorry invalid number entered Please enter a number from 1 to 9 \n Press enter to procced ");
                            break;
                    }
    		    	}
     
    		    	//generating a number to be played by computer
              		  int ran = 1 + (int)(Math.random() * 9);
    		    	//else
    		    		if(count==2)
    		    		{
    		    			 if (ran==1)
    		        		{
                                                button1.setText("O");
    				            button1.setEnabled(false);
     
    		       			 }
    				         else
    				         	if(ran==2)
    				       	{
    				             button2.setText("O");
    				             button2.setEnabled(false);
    				        }
    				         else
    				         	if(ran==3)
    				       	{
    				             button3.setText("0");
    				             button3.setEnabled(false);
    				        }
    				         else
    				         	if(ran==4)
    				       	{
    				             button4.setText("0");
    				             button4.setEnabled(false);
    				        }
    				         else
    				         	if(ran==5)
    				       	{
    				            button5.setText("0");
    				            button5.setEnabled(false);
    				        }
    				         else
    				         	if(ran==6)
    				       	{
    				             button6.setText("O");
    				             button6.setEnabled(false);
    				        }
    				         else
    				         	if(ran==7)
    				       	{
    				             button7.setText("X");
    				             button7.setEnabled(false);
    				        }
    				         else
    				         	if(ran==8)
    				       	{
    				             button8.setText("X");
    				             button8.setEnabled(false);
    				        }
    				         else
    				         	if(ran==9)
    				       	{
    				             button9.setText(letter);
    				             button9.setEnabled(false);
    				    	}
     
        				}
    	}
    	}
    	 public static void main(String[] args)
        {
            new TicT();
        }
     
     
    }


  2. #2
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: ERROR : "CLASS NAME IS ABSTRACT CANNOT BE INSTATIATED"

    Hi.
    Do you have knowledge about abstract classes?
    If not then this link shall help you Abstract Class, Abstraction, Abstract Class in Java, Abstract Method - Javatpoint.

    Thanks,
    Syed.

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ERROR : "CLASS NAME IS ABSTRACT CANNOT BE INSTATIATED"

    i get the picture now how should I modify it so that it does not mess up my project

  4. #4
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: ERROR : "CLASS NAME IS ABSTRACT CANNOT BE INSTATIATED"

    Hello.
    Did you go through that link? Doesn't it give hint on how to fix your problem?

    Syed.

  5. #5
    Member
    Join Date
    Jul 2013
    Location
    Franklin, TN
    Posts
    47
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Default Re: ERROR : "CLASS NAME IS ABSTRACT CANNOT BE INSTATIATED"

    If you won't read his tutorials I'll sum it up.

    You can't instantiate an abstract class because of that precisely.. it is abstract.
    Therefore you can't run your class at all because its intent is to be inherited.

    Read Syed's link and post back

  6. #6
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: ERROR : "CLASS NAME IS ABSTRACT CANNOT BE INSTATIATED"

    So you just decided to declare the class abstract even though you didn't understand what abstract classes were for?

    Can I ask, why?

    -summit45

  7. #7
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: ERROR : "CLASS NAME IS ABSTRACT CANNOT BE INSTATIATED"

    You can't create instances of abstract classes. You can extend them into concrete classes and use their methods and fields. I think you can also use them anonymously (that is, if you had another method named "addTict" that took a TicT object as a parameter, you could do something like addTicT(new Tict()).

    --- Update ---

    Quote Originally Posted by summit45 View Post
    So you just decided to declare the class abstract even though you didn't understand what abstract classes were for?

    Can I ask, why?

    -summit45
    I'm guessing the original poster didn't actually write that code.

Similar Threads

  1. "Error cannot find symbol" "throws BadLocationException"
    By coltson in forum AWT / Java Swing
    Replies: 1
    Last Post: June 30th, 2013, 10:33 PM
  2. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  3. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  4. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  5. Error of "class or interface expected" at Mylong class for problem of API's
    By lostgoat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 22nd, 2009, 08:28 PM