×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    47

    Global array not accessible

    Hi all,

    basic question...I'm a bit rusty with Java so bare with me.
    As far as I could remember, putting the keywork "public" before the variable should do this but in my application it isn't.

    See the code snippet here:

    Code:
    public class controller extends MIDlet implements TargetListener, CommandListener
    //public class controller extends MIDlet
    {
            public page navigatePages [] = new page [3];    //Holds the previous page, current page and next page, much like a web browsers history.
    Thanks in advance for any relevant views or opinions.

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Global array not accessible

    If the variable is marked Public it can accesses everywhere within the class and also outside the class with the Object of the class in which it is defined.

    If it's public static then in that case, it can directly used as className.variable from outside the class in the same package or imported/linked packages.

    thanks,
    ~Amitabh

  3. #3
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: Global array not accessible

    Quote Originally Posted by slugger_2003 View Post
    Hi all,

    basic question...I'm a bit rusty with Java so bare with me.
    As far as I could remember, putting the keywork "public" before the variable should do this but in my application it isn't.

    See the code snippet here:

    Code:
    public class controller extends MIDlet implements TargetListener, CommandListener
    //public class controller extends MIDlet
    {
            public page navigatePages [] = new page [3];    //Holds the previous page, current page and next page, much like a web browsers history.
    Thanks in advance for any relevant views or opinions.

    Please post your thread in more descriptive form,..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Global array not accessible

    Quote Originally Posted by slugger_2003 View Post
    Code:
    public class controller extends MIDlet implements TargetListener, CommandListener
    //public class controller extends MIDlet
    {
            public page navigatePages [] = new page [3];    //Holds the previous page, current page and next page, much like a web browsers history.
    Here is few basic and quick questions for you to answer, and to guess the reason for the issue,

    1. Have you created and defined the class page in you project?
    2. Was you project compile successfully?
    3. Or are you getting the error at the time of writing the code and IDE displays the RED lines at this point where you are trying to access this targeted array?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    47

    Re: Global array not accessible

    I was trying to utilise the variable navigatePages without creating an instance of it's container class, I thought this only needed to be done for private variables but was confusing it with public static. Consider this to be some rust removed from my Java hat...still in need of some oil though...

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Global array not accessible

    Quote Originally Posted by slugger_2003 View Post
    I was trying to utilise the variable navigatePages without creating an instance of it's container class, I thought this only needed to be done for private variables but was confusing it with public static. Consider this to be some rust removed from my Java hat...still in need of some oil though...
    Please explain, what do you mean to say
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    47

    Re: Global array not accessible

    I presume you had difficulty understanding my statement "Consider this to be some rust removed from my Java hat...still in need of some oil though". I basically meant that I had forgotten the rules of variable scope but now I remember.
    Problem is solved now though, thanks.

Similar Threads

  1. larger font ?
    By tanago in forum Symbian
    Replies: 2
    Last Post: 2010-01-09, 14:51
  2. Problem with Standalone App and smtplib
    By Karandaras in forum Symbian
    Replies: 5
    Last Post: 2009-10-07, 10:47
  3. How to declare array in header files
    By somnathbanik in forum Symbian
    Replies: 8
    Last Post: 2009-06-13, 04:12
  4. i am not getting the sprites more than two from array
    By want2win in forum Mobile Java Games
    Replies: 8
    Last Post: 2009-02-13, 07:24
  5. Global array of bitmaps to be used for in-game textures
    By abolfoooud in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2008-01-17, 13:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×