Results 1 to 5 of 5
  1. #1
    Mattedatten is offline Member
    Join Date
    Aug 2009
    Location
    South Sweden
    Posts
    24
    Rep Power
    0

    Post Cannot find symbol variable - Why? I can.. ^^

    Hello all
    I'm trying to do a simple, not very good at all, tictactoe game, but, i got the error in one of the classes (This isn't while compiling the main file and classes)
    Java Code:
    C:\Documents and Settings\26462\Mina dokument\Inte skolsaker\1x2\Spelkod.java:27: cannot find symbol
    symbol  : variable BotPos
    location: class Spelkod
    I have no idea why this happens, i've tried to move the code "BotPos" from one to another class-file, and i don't have any more clues what's wrong, any help?
    (Here is just one of the class-files, there are three, but the error is here somewhere)

    Java Code:
    import javax.swing.*;
    import java.io.*;
    import java.util.*;
    
    public class Spelkod
    {
    	public static void spel()
    	{
    		//Scanner som läser från kommandorutan
    		Scanner tangentbord = new Scanner(System.in);
    		
    		String a1 = " ";
    		String a2 = " ";
    		String a3 = " ";
    		
    		String b1 = " ";
    		String b2 = " ";
    		String b3 = " ";
    		
    		String c1 = " ";
    		String c2 = " ";
    		String c3 = " ";
    		
    		System.out.println("Where to put the X?");
    		String in = tangentbord.next();
    		Klasser.PassarRutval(in, a1, a2, a3, b1, b2, b3, c1, c2, c3);
    		[B]String botpos = Spelkod.BotPos;[/B]
    		while (true)
    		{
    			//Var ska botten sätta sin cirkel?
    			Klasser.PassarRutval(botpos, a1, a2, a3, b1, b2, b3, c1, c2, c3);
    			System.out.println("Where to put the X?");
    			in = tangentbord.next();
    			Klasser.PassarRutval(in, a1, a2, a3, b1, b2, b3, c1, c2, c3);
    			System.out.println("\n" + "_abc\n1:"+a1+b1+c1+"\n2:"+a2+b2+c2+"3:\n"+a3+b3+c3);
    			[B]botpos = Spelkod.BotPos;[/B]
    		}
    	}
    	[B]public static String BotPos ()[/B]
    	{
    		long numpos = Math.round(Math.random());
    		while (numpos<1 || numpos>3)
    		{
    			numpos = Math.round(Math.random());
    		}
    		
    		long bokpos = Math.round(Math.random());
    		while (bokpos<1 || bokpos>3)
    		{
    			bokpos = Math.round(Math.random());
    		}
    		if (bokpos == 1)
    			return "a"+numpos;
    		else if (bokpos == 2)
    			return "b" + numpos;
    		else if (bokpos == 3)
    			return "c"+numpos;
    		else
    		{
    			System.exit(0);
    			return "null";
    		}
    	}
    }
    Yes, this is a very unfunctional code, but this is my first attemt ever to do something like this, so these are my first tries to a solution ;)

    ///Mattedatten

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    You're calling a method, so:
    Java Code:
    String botpos = Spelkod.BotPos();
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    852000 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    as I know,the method :Math.random(),will gernerate a number during 0 to 1,so the condition : (numpos<1 || numpos>3) will never come true,so I think your code has something wrong

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by 852000 View Post
    as I know,the method :Math.random(),will gernerate a number during 0 to 1,so the condition : (numpos<1 || numpos>3) will never come true,so I think your code has something wrong

    if Math.random() generate numbers 0 to 1 then (numpos<1 || numpos>3) can surely become true, because || is a short-circuit evaluation of OR and if number is 0 then numpos<1 is true.

  5. #5
    Mattedatten is offline Member
    Join Date
    Aug 2009
    Location
    South Sweden
    Posts
    24
    Rep Power
    0

    Default

    Quote Originally Posted by PhHein View Post
    You're calling a method, so:
    Java Code:
    String botpos = Spelkod.BotPos();
    -sorry for late answer, been doing other stuff-
    Thanks, I could bet on something that the error was something small like this missing :eek:

    Quote Originally Posted by 852000 View Post
    as I know,the method :Math.random(),will gernerate a number during 0 to 1,so the condition : (numpos<1 || numpos>3) will never come true,so I think your code has something wrong
    Yes, true, forgot to add *10 for it all to make sense, thanks for pointing that out ;)

    Quote Originally Posted by j2me64 View Post
    if Math.random() generate numbers 0 to 1 then (numpos<1 || numpos>3) can surely become true, because || is a short-circuit evaluation of OR and if number is 0 then numpos<1 is true.
    Well, that also :rolleyes:

    Thanks all, I do really appreciate the help and explanation on these forums :)
    Thanks again

Similar Threads

  1. Error "can not find symbol variable"
    By FullMetalHollow in forum New To Java
    Replies: 5
    Last Post: 10-04-2009, 09:51 PM
  2. Cannot find symbol variable pD! I cant fix it!!!
    By Addez in forum New To Java
    Replies: 2
    Last Post: 09-17-2009, 08:32 PM
  3. Cannot find symbol variable yourScore
    By Addez in forum New To Java
    Replies: 4
    Last Post: 08-17-2009, 10:48 PM
  4. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 08:30 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
  •