LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2011, 12:05 PM   #1
puppymagic
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 66

Rep: Reputation: 4
Question It appears integer variable i is not visible


Code:
for(int i = 0; i<9;i++) {

        b[i].setOnClickListener(

            new OnClickListener()
            {
                public void onClick(View v)
                {

                    justclicked(i);

                }
            }


                );

    }

I am attempting to put an action listener on nine buttons using a for loop. The code above is giving me an error. Is the error caused by the value of i not being visible in justclicked(i)?? Thanks a lot, world-class experts @ Linux Questions!!

Last edited by puppymagic; 10-18-2011 at 12:06 PM.
 
Old 10-18-2011, 12:30 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
The code above is giving me an error.
Please post the exact error when asking questions. In this case I would guess the error is something like:
Quote:
local variable i is accessed from within inner class; needs to be declared final
Which is caused by trying to access a non-final variable from an inner class.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
variable integer tostay2003 Programming 4 11-26-2008 06:14 PM
php global variable appears in every html form with firefox 3.0.3 baikonur Programming 1 11-02-2008 05:16 AM
script doesn't want to see my variable as an integer. Xerop Linux - Software 5 09-08-2008 04:58 AM
Test variable is an integer in shell judgex Programming 1 06-03-2006 09:12 PM
write() a variable(integer) to socket? koyi Programming 6 07-08-2004 09:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration