Results 1 to 5 of 5
  1. #1
    TheBadBoy is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Exclamation Help with my Tic Tac Toe program-null pointer exception

    I have made a program to play Tic Tac Toe game but it gives me a run time error. Please help me. Here goes my code:
    Java Code:
    import java.io.*;
    class TicTacToe
    {
        static BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        static int p,q,w,e,r,t,y,u,i,o,z,mnb,qqq=1;
        static String a,s,d,f,g,h,j,k,l,m,qqqqqqqq;
        static double c;
        static void CompChance()
        {
            System.out.println("Computer's turn is first. Your symbol is \"0\". The Grid is:-\n\t_|_|_\n\t_|_|_\n\t | | \n");
            qwerty:
          for(;;)
          {try
              {
            for(int loop=1;loop<=4;loop++)
            {
                System.out.print("Computer's turn. The computer is thinking.");
                 Thread.sleep(500);
                 System.out.print(".");
                 Thread.sleep(500);
                 System.out.println(".");
                 System.out.println("\n\n");
                 inner:
                 for(;;)
                 {
                     if(qqq==1)
                     {
                         if((a==s&&a.equals("X"))||(h==l&&h.equals("X"))||(j==g&&j.equals("X")))
                         {p=3;qqq++;}
                         else if((a==d&&a.equals("X"))||(g==k&&k.equals("X")))
                         {p=2;qqq++;}
                         else if((d==s&&d.equals("X"))||(g==l&&g.equals("X"))||(j==f&&j.equals("X")))
                         {p=1;qqq++;}
                         else if((g==h&&g.equals("X"))||(a==j&&a.equals("X")))
                         {p=4;qqq++;}
                         else if((a==l&&a.equals("X"))||(s==k&&s.equals("X"))||(f==h&&h.equals("X")))
                         {p=5;qqq++;}
                         else if((d==l&&d.equals("X"))||(f==g&&g.equals("X")))
                         {p=6;qqq++;}
                         else if((a==f&&a.equals("X"))||(k==l&&k.equals("X"))||(d==g&&d.equals("X")))
                         {p=7;qqq++;}
                         else if((g==s&&g.equals("X"))||(j==l&&j.equals("X")))
                         {p=8;qqq++;}
                         else if((a==s&&a.equals("0"))||(h==l&&h.equals("0"))||(j==g&&j.equals("0")))
                         {p=3;qqq++;}
                         else if((a==d&&a.equals("0"))||(g==k&&k.equals("0")))
                         {p=2;qqq++;}
                         else if((d==s&&d.equals("0"))||(g==l&&g.equals("0"))||(j==f&&j.equals("0")))
                         {p=1;qqq++;}
                         else if((g==h&&g.equals("0"))||(a==j&&a.equals("0")))
                         {p=4;qqq++;}
                         else if((a==l&&a.equals("0"))||(s==k&&s.equals("0"))||(f==h&&h.equals("0")))
                         {p=5;qqq++;}
                         else if((d==l&&d.equals("0"))||(f==g&&g.equals("0")))
                         {p=6;qqq++;}
                         else if((a==f&&a.equals("0"))||(k==l&&k.equals("0"))||(d==g&&d.equals("0")))
                         {p=7;qqq++;}
                         else if((g==s&&g.equals("0"))||(j==l&&j.equals("0")))
                         {p=8;qqq++;}
                         else
                         {p=9;qqq++;}
                     }
                     else
                     {
                         c=Math.random();
                         if(c<0.12)
                          p=1;
                         else if(c<0.24)
                          p=2;
                         else if(c<0.36)
                          p=3;
                         else if(c<0.47)
                          p=4;
                         else if(c<0.587)
                          p=5;
                         else if(c<0.7001)
                          p=6;
                         else if(c<0.8)
                          p=7;
                         else if(c<9)
                          p=8;
                         else
                          p=9;
                     }
                     if(p==q)
                      continue inner;
                     else if(i==p)
                      continue inner;
                     else if(o==p)
                      continue inner;
                     else if(u==p)
                      continue inner;
                     else if(y==p)
                      continue inner;
                     else if(t==p)
                      continue inner;
                     else if(p==r)
                      continue inner;
                     else if(p==e)
                      continue inner;
                     else if(p==w)
                      continue inner;
                     else
                      {qqq=1;break;}
                 }
                 System.out.println("The computer has chosen "+p+" as his position");
                 if(p==1)
                 {a="X";q=1;}
                 else if(p==2)
                 {s="X";w=p;}
                 else if(p==3)
                 {d="X";e=p;}
                 else if(p==4)
                 {f="X";r=p;}
                 else if(p==5)
                 {g="X";t=p;}
                 else if(p==6)
                 {h="X";y=p;}
                 else if(p==7)
                 {j="X";u=p;}
                 else if(p==8)
                 {k="X";i=p;}
                 else if(p==9)
                 {l="X";o=p;}
                 System.out.println("\n\t"+a+m+s+m+d+"\n\t"+f+m+g+m+h+"\n\t"+j+m+k+m+l);
                 if(a=="X"&&s==a&&d==a)
                  z=1;
                 else if(f=="X"&&g==f&&h==f)
                  z=1;
                 else if(j=="X"&&k==j&&l==j)
                  z=1;
                 else if(a=="X"&&f==a&&j==f)
                  z=1;
                 else if(s=="X"&&g==s&&k==g)
                  z=1;
                 else if(d=="X"&&h==d&&l==d)
                  z=1;
                 else if(a=="X"&&g==a&&l==a)
                  z=1;
                 else if(d=="X"&&g==d&&j==g)
                  z=1;
                 if(z==1)
                 {
                       System.out.println("*************You Lose****************");
                       {System.out.println("It is now safe to close this window.");System.exit(0);}
                 }
                 System.out.println();
                 System.out.println("Enter a position to place your symbol:");
                 p=Integer.parseInt(buf.readLine());
                 if(p==0)
                 {System.out.println("It is now safe to close this window.");System.exit(0);}
                 if(p==q)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(i==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(o==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(u==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(y==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(t==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(p==r)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(p==e)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(p==w)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 else if(p==1)
                 {a="0";q=1;}
                 else if(p==2)
                 {s="0";w=p;}
                 else if(p==3)
                 {d="0";e=p;}
                 else if(p==4)
                 {f="0";r=p;}
                 else if(p==5)
                 {g="0";t=p;}
                 else if(p==6)
                 {h="0";y=p;}
                 else if(p==7)
                 {j="0";u=p;}
                 else if(p==8)
                 {k="0";i=p;}
                 else if(p==9)
                 {l="0";o=p;}
                 System.out.println("\n\t"+a+m+s+m+d+"\n\t"+f+m+g+m+h+"\n\t"+j+m+k+m+l);
                 if(a=="0"&&s==a&&d==a)
                  z=1;
                 else if(f=="0"&&g==f&&h==f)
                  z=1;
                 else if(j=="0"&&k==j&&l==j)
                  z=1;
                 else if(a=="0"&&f==a&&j==f)
                  z=1;
                 else if(s=="0"&&g==s&&k==g)
                  z=1;
                 else if(d=="0"&&h==d&&l==d)
                  z=1;
                 else if(a=="0"&&g==a&&l==a)
                  z=1;
                 else if(d=="0"&&g==d&&j==g)
                  z=1;
                 if(z==1)
                 {
                       System.out.println("\n");
                       System.out.println("*************You Won****************");
                       {System.out.println("It is now safe to close this window.");System.exit(0);}
                 }
                 System.out.println("\n");
            }
            System.out.print("Computer's turn. The computer is thinking.");
            Thread.sleep(500);
            System.out.print(".");
            Thread.sleep(500);
            System.out.println(".");
            System.out.println("\n\n");
            inner:
            for(;;)
            {
                if(qqq==1)
                {
                     if((a==s&&a.equals("X"))||(h==l&&h.equals("X"))||(j==g&&j.equals("X")))
                     {p=3;qqq++;}
                     else if((a==d&&a.equals("X"))||(g==k&&k.equals("X")))
                     {p=2;qqq++;}
                     else if((d==s&&d.equals("X"))||(g==l&&g.equals("X"))||(j==f&&j.equals("X")))
                     {p=1;qqq++;}
                     else if((g==h&&g.equals("X"))||(a==j&&a.equals("X")))
                     {p=4;qqq++;}
                     else if((a==l&&a.equals("X"))||(s==k&&s.equals("X"))||(f==h&&h.equals("X")))
                     {p=5;qqq++;}
                     else if((d==l&&d.equals("X"))||(f==g&&g.equals("X")))
                     {p=6;qqq++;}
                     else if((a==f&&a.equals("X"))||(k==l&&k.equals("X"))||(d==g&&d.equals("X")))
                     {p=7;qqq++;}
                     else if((g==s&&g.equals("X"))||(j==l&&j.equals("X")))
                     {p=8;qqq++;}
                     else if((a==s&&a.equals("0"))||(h==l&&h.equals("0"))||(j==g&&j.equals("0")))
                     {p=3;qqq++;}
                     else if((a==d&&a.equals("0"))||(g==k&&k.equals("0")))
                     {p=2;qqq++;}
                     else if((d==s&&d.equals("0"))||(g==l&&g.equals("0"))||(j==f&&j.equals("0")))
                     {p=1;qqq++;}
                     else if((g==h&&g.equals("0"))||(a==j&&a.equals("0")))
                     {p=4;qqq++;}
                     else if((a==l&&a.equals("0"))||(s==k&&s.equals("0"))||(f==h&&h.equals("0")))
                     {p=5;qqq++;}
                     else if((d==l&&d.equals("0"))||(f==g&&g.equals("0")))
                     {p=6;qqq++;}
                     else if((a==f&&a.equals("0"))||(k==l&&k.equals("0"))||(d==g&&d.equals("0")))
                     {p=7;qqq++;}
                     else if((g==s&&g.equals("0"))||(j==l&&j.equals("0")))
                     {p=8;qqq++;}
                     else
                     {p=9;qqq++;}
                }
                else
                {
                      c=Math.random();
                      if(c<0.12)
                       p=1;
                      else if(c<0.24)
                       p=2;
                      else if(c<0.36)
                       p=3;
                      else if(c<0.47)
                       p=4;
                      else if(c<0.587)
                       p=5;
                      else if(c<0.7001)
                       p=6;
                      else if(c<0.8)
                       p=7;
                      else if(c<9)
                       p=8;
                      else
                       p=9;
                }
                if(p==q)
                 continue inner;
                else if(i==p)
                 continue inner;
                else if(o==p)
                 continue inner;
                else if(u==p)
                 continue inner;
                else if(y==p)
                 continue inner;
                else if(t==p)
                 continue inner;
                else if(p==r)
                 continue inner;
                else if(p==e)
                 continue inner;
                else if(p==w)
                 continue inner;
                else
                {qqq=1;break;}
            }
            System.out.println("The computer has chosen "+p+" as his position");
            if(p==1)
            {a="X";q=1;}
            else if(p==2)
            {s="X";w=p;}
            else if(p==3)
            {d="X";e=p;}
            else if(p==4)
            {f="X";r=p;}
            else if(p==5)
            {g="X";t=p;}
            else if(p==6)
            {h="X";y=p;}
            else if(p==7)
            {j="X";u=p;}
            else if(p==8)
            {k="X";i=p;}
            else if(p==9)
            {l="X";o=p;}
            System.out.println("\n\t"+a+m+s+m+d+"\n\t"+f+m+g+m+h+"\n\t"+j+m+k+m+l);
            if(a=="X"&&s==a&&d==a)
             z=1;
            else if(f=="X"&&g==f&&h==f)
             z=1;
            else if(j=="X"&&k==j&&l==j)
             z=1;
            else if(a=="X"&&f==a&&j==f)
             z=1;
            else if(s=="X"&&g==s&&k==g)
             z=1;
            else if(d=="X"&&h==d&&l==d)
             z=1;
            else if(a=="X"&&g==a&&l==a)
             z=1;
            else if(d=="X"&&g==d&&j==g)
             z=1;
            if(z==1)
            {
                  System.out.println("*************You Lose****************");
                  {System.out.println("It is now safe to close this window.");System.exit(0);}
            }
            System.out.println();
        }
        catch(InterruptedException IntExp)
        {
            System.out.println("An error had occured.. ERROR: "+IntExp+".\n Restarting the game...");
            continue qwerty;
        }
        catch(IOException IOExp)
        {
            System.out.println("An error had occured.. ERROR: "+IOExp+".\n Restarting the game...");
            continue qwerty;
        }
    }
    }
        static void PlayerChance()
        {
          qwerty:
          for(;;)
          {
              try
          {
            System.out.println("Your turn. Your symbol is \"X\". The Grid is:-\n\t_|_|_\n\t_|_|_\n\t | | \n");
            System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n");
            for(int loop=1;loop<=4;loop++)
            {
                 System.out.println("Enter a position to place your symbol:");
                 p=Integer.parseInt(buf.readLine());
                 if(p==0)
                 {System.out.println("It is now safe to close this window.");System.exit(0);}
                 if(p==q)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(i==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(o==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(u==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(y==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(t==p)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(p==r)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(p==e)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 if(p==w)
                 {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
                 else if(p==1)
                 {a="X";q=1;}
                 else if(p==2)
                 {s="X";w=p;}
                 else if(p==3)
                 {d="X";e=p;}
                 else if(p==4)
                 {f="X";r=p;}
                 else if(p==5)
                 {g="X";t=p;}
                 else if(p==6)
                 {h="X";y=p;}
                 else if(p==7)
                 {j="X";u=p;}
                 else if(p==8)
                 {k="X";i=p;}
                 else if(p==9)
                 {l="X";o=p;}
                 System.out.println("\n\t"+a+m+s+m+d+"\n\t"+f+m+g+m+h+"\n\t"+j+m+k+m+l);
                 if(a=="X"&&s==a&&d==a)
                  z=1;
                 else if(f=="X"&&g==f&&h==f)
                  z=1;
                 else if(j=="X"&&k==j&&l==j)
                  z=1;
                 else if(a=="X"&&f==a&&j==f)
                  z=1;
                 else if(s=="X"&&g==s&&k==g)
                  z=1;
                 else if(d=="X"&&h==d&&l==d)
                  z=1;
                 else if(a=="X"&&g==a&&l==a)
                  z=1;
                 else if(d=="X"&&g==d&&j==g)
                  z=1;
                 if(z==1)
                 {
                       System.out.println("\n");
                       System.out.println("*************You Won****************");
                       {System.out.println("It is now safe to close this window.");System.exit(0);}
                 }
                 System.out.println("\n");
                 System.out.print("Computer's turn. The computer is thinking.");
                 Thread.sleep(500);
                 System.out.print(".");
                 Thread.sleep(500);
                 System.out.println(".");
                 System.out.println("\n\n");
                 inner:
                 for(;;)
                 {
                     if(qqq==1)
                     {
                         if((a==s&&a.equals("0"))||(h==l&&h.equals("0"))||(j==g&&j.equals("0")))
                         {p=3;qqq++;}
                         else if((a==d&&a.equals("0"))||(g==k&&k.equals("0")))
                         {p=2;qqq++;}
                         else if((d==s&&d.equals("0"))||(g==l&&g.equals("0"))||(j==f&&j.equals("0")))
                         {p=1;qqq++;}
                         else if((g==h&&g.equals("0"))||(a==j&&a.equals("0")))
                         {p=4;qqq++;}
                         else if((a==l&&a.equals("0"))||(s==k&&s.equals("0"))||(f==h&&h.equals("0")))
                         {p=5;qqq++;}
                         else if((d==l&&d.equals("0"))||(f==g&&g.equals("0")))
                         {p=6;qqq++;}
                         else if((a==f&&a.equals("0"))||(k==l&&k.equals("0"))||(d==g&&d.equals("0")))
                         {p=7;qqq++;}
                         else if((g==s&&g.equals("0"))||(j==l&&j.equals("0")))
                         {p=8;qqq++;}
                         else if((a==s&&a.equals("X"))||(h==l&&h.equals("X"))||(j==g&&j.equals("X")))
                         {p=3;qqq++;}
                         else if((a==d&&a.equals("X"))||(g==k&&k.equals("X")))
                         {p=2;qqq++;}
                         else if((d==s&&d.equals("X"))||(g==l&&g.equals("X"))||(j==f&&j.equals("X")))
                         {p=1;qqq++;}
                         else if((g==h&&g.equals("X"))||(a==j&&a.equals("X")))
                         {p=4;qqq++;}
                         else if((a==l&&a.equals("X"))||(s==k&&s.equals("X"))||(f==h&&h.equals("X")))
                         {p=5;qqq++;}
                         else if((d==l&&d.equals("X"))||(f==g&&g.equals("X")))
                         {p=6;qqq++;}
                         else if((a==f&&a.equals("X"))||(k==l&&k.equals("X"))||(d==g&&d.equals("X")))
                         {p=7;qqq++;}
                         else if((g==s&&g.equals("X"))||(j==l&&j.equals("X")))
                         {p=8;qqq++;}
                         else
                         {p=9;qqq++;}
                     }
                     else
                     {
                         c=Math.random();
                         if(c<0.12)
                          p=1;
                         else if(c<0.24)
                          p=2;
                         else if(c<0.36)
                          p=3;
                         else if(c<0.47)
                          p=4;
                         else if(c<0.587)
                          p=5;
                         else if(c<0.7001)
                          p=6;
                         else if(c<0.8)
                          p=7;
                         else if(c<9)
                          p=8;
                         else
                          p=9;
                     }
                     if(p==q)
                      continue inner;
                     else if(i==p)
                      continue inner;
                     else if(o==p)
                      continue inner;
                     else if(u==p)
                      continue inner;
                     else if(y==p)
                      continue inner;
                     else if(t==p)
                      continue inner;
                     else if(p==r)
                      continue inner;
                     else if(p==e)
                      continue inner;
                     else if(p==w)
                      continue inner;
                     else
                      {qqq=1;break;}
                 }
                 System.out.println("The computer has chosen "+p+" as his position");
                 if(p==1)
                 {a="0";q=1;}
                 else if(p==2)
                 {s="0";w=p;}
                 else if(p==3)
                 {d="0";e=p;}
                 else if(p==4)
                 {f="0";r=p;}
                 else if(p==5)
                 {g="0";t=p;}
                 else if(p==6)
                 {h="0";y=p;}
                 else if(p==7)
                 {j="0";u=p;}
                 else if(p==8)
                 {k="0";i=p;}
                 else if(p==9)
                 {l="0";o=p;}
                 System.out.println("\n\t"+a+m+s+m+d+"\n\t"+f+m+g+m+h+"\n\t"+j+m+k+m+l);
                 if(a=="0"&&s==a&&d==a)
                  z=1;
                 else if(f=="0"&&g==f&&h==f)
                  z=1;
                 else if(j=="0"&&k==j&&l==j)
                  z=1;
                 else if(a=="0"&&f==a&&j==f)
                  z=1;
                 else if(s=="0"&&g==s&&k==g)
                  z=1;
                 else if(d=="0"&&h==d&&l==d)
                  z=1;
                 else if(a=="0"&&g==a&&l==a)
                  z=1;
                 else if(d=="0"&&g==d&&j==g)
                  z=1;
                 if(z==1)
                 {
                       System.out.println("*************You Lose****************");
                       {System.out.println("It is now safe to close this window.");System.exit(0);}
                 }
                 System.out.println();
                }
            System.out.println("Enter a position to place your symbol:");
            p=Integer.parseInt(buf.readLine());
            if(p==0)
            {System.out.println("It is now safe to close this window.");System.exit(0);}
            if(p==q)
            {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
            if(i==p)
            {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
            if(o==p)
            {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
            if(u==p)
            {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
            if(y==p)
            {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
            if(t==p)
            {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
            if(p==r)
            {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
            if(p==e)
            {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
            if(p==w)
            {System.out.println("Error occured.. Restarting the game...");continue qwerty;}
            else if(p==1)
            {a="X";q=1;}
            else if(p==2)
            {s="X";w=p;}
            else if(p==3)
            {d="X";e=p;}
            else if(p==4)
            {f="X";r=p;}
            else if(p==5)
            {g="X";t=p;}
            else if(p==6)
            {h="X";y=p;}
            else if(p==7)
            {j="X";u=p;}
            else if(p==8)
            {k="X";i=p;}
            else if(p==9)
            {l="X";o=p;}
            System.out.println("\n\t"+a+m+s+m+d+"\n\t"+f+m+g+m+h+"\n\t"+j+m+k+m+l);
            if(a=="X"&&s==a&&d==a)
             z=1;
            else if(f=="X"&&g==f&&h==f)
             z=1;
            else if(j=="X"&&k==j&&l==j)
             z=1;
            else if(a=="X"&&f==a&&j==f)
             z=1;
            else if(s=="X"&&g==s&&k==g)
             z=1;
            else if(d=="X"&&h==d&&l==d)
             z=1;
            else if(a=="X"&&g==a&&l==a)
             z=1;
            else if(d=="X"&&g==d&&j==g)
             z=1;
            if(z==1)
            {
                  System.out.println("\n");
                  System.out.println("*************You Won****************");
                  {System.out.println("It is now safe to close this window.");System.exit(0);}
            }
            System.out.println("\n");
            }
        catch(InterruptedException IntExp)
        {
            System.out.println("An error had occured.. ERROR: "+IntExp+".\n Restarting the game...");
            continue qwerty;
        }
        catch(IOException IOExp)
        {
            System.out.println("An error had occured.. ERROR: "+IOExp+".\n Restarting the game...");
            continue qwerty;
        }
         }
        }
        TicTacToe()
        {
            p=0;o=p;i=p;u=p;y=p;t=p;r=p;e=p;w=p;q=p;z=0;
            a="_";s=a;d=a;f=a;g=a;h=g;j=" ";k=j;l=k;m="|";c=Math.random();
        }
        static void UDecide()
        {
            System.out.print("Congrats!! Computer has gifted you a special advantage to decide who will place the symbol first on the grid board..\nPlease enter \"ME\" or \"1\" for yourself OR \"COMP\" or \"2\" for computer..\nYour input:");
            for(;;)
            {
            try
            {
            
                 qqqqqqqq=buf.readLine();
                 if(qqqqqqqq.equalsIgnoreCase("me")||qqqqqqqq.equals("1"))
                      PlayerChance();
                 else if(qqqqqqqq.equalsIgnoreCase("comp")||qqqqqqqq.equals("2"))
                      CompChance();
                 else
                 {
                      System.out.println("Please Provide A Valid Input.. Retry?");
                      continue;
                 }
            
        }
        catch(IOException uyt)
        {
            System.out.println("An Error Has Occured.. Please Retry?");
            continue;
        }
    }
    }
        static void chance()
        {
            if(c==5.0)
            UDecide();
            else if(c<=5.0)
            PlayerChance();
            else
            CompChance();
        }
        static void review()
        {
            System.out.println("The basic grid is like this:");
            System.out.println("\n\t1|2|3\n\t4|5|6\n\t7|8|9");
            System.out.println("The numbers(1-9) repesents the positions.");
            System.out.println("Note that you can exit anytime by pressing ZERO(0) key.");
        }
        public static void main(String args[])
        {
            for(;;)
            {try
            {
                System.out.println(" ***M E N U***");
                System.out.print("1. Start Playing\n2. Game Help\n3. Exit\n Enter your choice:");
                String cv=buf.readLine();
                if(cv.equals("1"))
                {
                    chance();
                }
                else if(cv.equals("2"))
                {
                    review();
                }
                else if(cv.equals("3"))
                {
                    System.out.println("It is now safe to close this window.");
                    System.exit(0);
                }
                else
                {System.out.println("Error.. Redisplaying main menu");continue;}
            }
            catch(IOException uuuu)
            {
                System.out.println("An Error has occured.. Please Retry?");
                continue;
            }
        }
       }
    }
    .
    .
    .
    .
    .
    .
    .
    .
    .
    BlueJ shows this error message in its terminal window-

    java.lang.NullPointerException
    at TicTacToe.PlayerChance(TicTacToe.java:443)
    at TicTacToe.chance(TicTacToe.java:678)
    at TicTacToe.main(TicTacToe.java:699)

  2. #2
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    Are you serious, or just trolling?

  3. #3
    TheBadBoy is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Re:#2
    What do you think? This is my first post on the forum and that's why I couldn't be trolling. So please help me out.
    Last edited by TheBadBoy; 06-10-2011 at 06:33 PM.

  4. #4
    TheBadBoy is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Now I have found the solution. The problem was that I have not called the constructor and hence the global variables holded a null value. Now the code is working working fine.

  5. #5
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    What do you think?
    Well, I didn't know - that's why I asked.

    --------

    If you are serious the best help I can offer is the suggestion that you name the variables and set out and document the code in a way that makes it readable. See, for instance, Oracle's Code COnventions for the Java Programming Language.

    In any event I'm glad you've got the variables initialised now.

Similar Threads

  1. null pointer exception
    By bequick01 in forum New To Java
    Replies: 3
    Last Post: 04-28-2011, 09:31 PM
  2. Null Pointer exception (Again !!)
    By mobosecomin in forum New To Java
    Replies: 6
    Last Post: 03-29-2011, 06:04 PM
  3. Null pointer exception
    By jessie in forum New To Java
    Replies: 5
    Last Post: 02-08-2011, 03:58 PM
  4. null pointer exception
    By jyothi.priyanka in forum New To Java
    Replies: 12
    Last Post: 03-11-2009, 06:04 PM
  5. getting a null pointer exception
    By Rjava in forum XML
    Replies: 4
    Last Post: 07-16-2008, 06:56 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
  •