Results 1 to 2 of 2
- 04-30-2012, 01:56 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 1
- Rep Power
- 0
cannot find symbol ( looking for quick help)
Hey everyone,
I stuck with a very common problem ( as far I searched ) but I can't find the reason . I would be thankful with any help.
here is my code
Java Code:import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.*; import java.io.*; public class GeneratePattern { private final static int STATE_ON = 1; private final static int STATE_OFF = 0; private final static int SEED_CHOICE = 1; private final static int RANDOM_CHOICE = 2; private final static int CA_LOWER_BOUNDARY = 2; private final static int CA_UPPER_BOUNDARY = 81; private final static int ROW_IN_CA = 16; private final static int COL_IN_CA = 84; //This is used to store the key along with their states as per given rule...... static HashMap<String,Integer> state_identification = new HashMap<String, Integer>(); //Initializing all states to ZERO initially, later we'll set the states according to rule given by user. //The graph to be generate private static int wolfran_Graph[][] = new int[17][84]; public static void main(String[] args) { //This is used to store the key along with their states as per given rule...... HashMap<String,Integer> state_identification = new HashMap<String, Integer>(); int r; System.out.println("Input Radius 1 or 2:"); Scanner input1= new Scanner(System.in); r = input1.nextInt(); if ( r==1) { String neighbours_identifion[]={ "000","001","010","011","100","101","110","111",}; } else if ( r==2) { String neighbours_identifion[]={ "00000","00001","00010","00011","00100","00101","00110","00111", "01000","01001","01010","01011","01100","01101","01110","01111", "10000","10001","10010","10011","10100","10101","10110","10111", "11000","11001","11010","11011","11100","11101","11110","11111", }; } int length = 0 ; while(neighbours_identifion.length > length){ state_identification.put(neighbours_identifion[length], STATE_OFF); length++; } InputStreamReader input = new InputStreamReader(System.in); BufferedReader reader = new BufferedReader(input); // User should enter some rule first, it must be an integer. int rule = 0; System.out.println("Input Rule:"); try { rule = Integer.parseInt(reader.readLine()); } catch(IOException e){ e.printStackTrace(); } String binary = Integer.toBinaryString(rule); int ruleLength = binary.length()-1; for(int i = ruleLength ; i >= 0 ; i--){ if(binary.charAt(i) == '1') { state_identification.put(neighbours_identifion[ruleLength-i], STATE_ON); } } System.out.println("choice 1 : Enter 1 for select Seed...cell[42]...\n" + "choice 2: Enter 2 for random starting condition..."); do{ int userChoice = SEED_CHOICE; try { userChoice = Integer.parseInt(reader.readLine()); } catch(IOException e){ e.printStackTrace(); } if(SEED_CHOICE == userChoice){ wolfran_Graph[0][42] = STATE_ON; break; } if(RANDOM_CHOICE == userChoice){ //Here we are filling 10 random cells... int randomPosition; for(int i=0 ; i < 10; i++) { randomPosition = CA_LOWER_BOUNDARY + (int)(Math.random() * CA_UPPER_BOUNDARY); wolfran_Graph[0][randomPosition] = STATE_ON; } break; } }while(true); for(int row = 0 ; row < ROW_IN_CA ; row ++){ generateAutomata(row); } printCA(); } //Function used to generate Cellular automata. private static void generateAutomata(int row){ for(int col = CA_LOWER_BOUNDARY ; col <= CA_UPPER_BOUNDARY ; col++) { String key = "" + wolfran_Graph[row][col-2] + wolfran_Graph[row][col-1] + wolfran_Graph[row][col] + wolfran_Graph[row][col + 1] + wolfran_Graph[row][col+2] ; if(checkforState(key)){ wolfran_Graph[row + 1][col] = STATE_ON; } } } //Function used to check for state of a given key pair in CA..... private static boolean checkforState(String key){ if(state_identification.get(key) == STATE_ON){ return true; } else return false; } //Function used to print cellular automata...... private static void printCA(){ for(int row = 0 ; row < ROW_IN_CA ; row++){ for(int col = 0 ; col < COL_IN_CA ; col++){ System.out.print(wolfran_Graph[row][col]); } System.out.println(); } } }
I need to get the radius ( -variable r) and based on the input define my string array . but every time I run it it comes up with error;
eneratePattern.java:78: cannot find symbol
symbol : variable neighbours_identification
location: class GeneratePattern
while(neighbours_identification.length > length){
^
GeneratePattern.java:79: cannot find symbol
symbol : variable neighbours_identification
location: class GeneratePattern
state_identification.put(neighbours_identification[length], STATE_OFF);
^
GeneratePattern.java:104: cannot find symbol
symbol : variable neighbours_identification
location: class GeneratePattern
state_identification.put(neighbours_identification[ruleLength-i], STATE_ON);
^
3 errors
-
Re: cannot find symbol ( looking for quick help)
You appear to have a scope problem. The variable you're trying to access, neighbours_identification, was declared in an if block and is thus only visible within that if block. If you need to handle it outside of the if block, you must declare it outside of (before) the block.
Java Code:int widerScopeVariable = 2; if (foo == baz) { // localScopeVariable is *only* visible in this if block int localScopeVariable = 3; // widerScopeVariable is visible inside and outside of this block // since it was declared outside of the block widerScopeVariable = 6; } System.out.println("widerScopeVariable is " + widerScopeVariable); // this works! System.out.println("localScopeVariable is " + localScopeVariable); // this doesn't!Last edited by Fubarable; 04-30-2012 at 02:32 AM.
Similar Threads
-
Cannot find symbol
By Eleeist in forum New To JavaReplies: 5Last Post: 01-22-2012, 08:36 PM -
cannot find symbol
By LimblessQuasar in forum New To JavaReplies: 4Last Post: 06-11-2011, 10:55 PM -
Cannot Find Symbol
By Promisha in forum New To JavaReplies: 10Last Post: 03-30-2011, 02:11 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 08:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks