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 6 of 6

Thread: cannoot find symbol

  1. #1
    Member
    Join Date
    Mar 2014
    Posts
    70
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default cannoot find symbol

    Hi.
    What's wrong with:
    	public void showResults(Info[] queue,int k)
    	{
     
    		String results = "";
    		for(int i =0;i<queue.length;++i)
    		if(nameChecked)
    		  results += queue[i].name;
    		if(archChecked)
    		    results += queue[i].arch;
    		if(versionChecked)
    		    results += queue[i].version; 
    	}
    I cannot understand compiler hints

    EDIT:
    sysinfoHooshi.java:162: cannot find symbol
    symbol : variable i
    location: class sysinfoHooshi
    results += queue[i].arch;
    ^


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: cannoot find symbol

    Again, the compiler doesn't "hint" anything. It gives you very specific errors.

    What symbol can't it find? You'll have much better luck if you post an MCVE instead of incomplete code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    567
    Thanks
    0
    Thanked 104 Times in 89 Posts

    Default Re: cannoot find symbol

    The error message is pretty clear, the variable "i" is never defined when you try to use it. Just look at your code very closely, and you will see that i is not visible everywhere where it is used.
    This would be your code with proper brackets:
    	public void showResults(Info[] queue,int k)
    	{
     
    		String results = "";
    		for(int i =0;i<queue.length;++i) {
    			if(nameChecked)
    			  results += queue[i].name;
    		}
    		if(archChecked)
    		    results += queue[i].arch;
    		if(versionChecked)
    		    results += queue[i].version; 
    	}

  4. #4
    Member
    Join Date
    Mar 2014
    Posts
    70
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: cannoot find symbol

    Quote Originally Posted by Cornix View Post
    The error message is pretty clear, the variable "i" is never defined when you try to use it. Just look at your code very closely, and you will see that i is not visible everywhere where it is used.
    This would be your code with proper brackets:
    	public void showResults(Info[] queue,int k)
    	{
     
    		String results = "";
    		for(int i =0;i<queue.length;++i) {
    			if(nameChecked)
    			  results += queue[i].name;
    		}
    		if(archChecked)
    		    results += queue[i].arch;
    		if(versionChecked)
    		    results += queue[i].version; 
    	}
    Eh...I haven't defined it?Look inside for-loop...I have. haven't I? I have.....seemingly, unless it goes out of scope

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: cannoot find symbol

    Quote Originally Posted by hooshdar3 View Post
    unless it goes out of scope
    It does. This is why you should always use curly brackets with if statements and for loops.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    567
    Thanks
    0
    Thanked 104 Times in 89 Posts

    Default Re: cannoot find symbol

    Quote Originally Posted by hooshdar3 View Post
    Eh...I haven't defined it?Look inside for-loop...I have. haven't I? I have.....seemingly, unless it goes out of scope
    Look at my correction of your code, you might notice that the line:
    results += queue[i].arch;
    tries to use a variable i which has not been defined in the same scope.

Similar Threads

  1. [SOLVED] cannot find symbol
    By ATIBA SHEIKH in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 26th, 2012, 02:28 AM
  2. [SOLVED] Cannot Find Symbol
    By ChicoTheMan94 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 25th, 2012, 02:46 PM
  3. Cannot find symbol
    By waarten in forum What's Wrong With My Code?
    Replies: 18
    Last Post: January 11th, 2012, 02:15 PM
  4. Cannot find Symbol?
    By defmetalhead in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 5th, 2011, 08:48 AM
  5. Cannot find symbol?
    By stealthmonkey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 10th, 2010, 09:02 PM