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

Thread: how to use getResources() in setters and getters

  1. #1
    Junior Member
    Join Date
    Sep 2019
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default how to use getResources() in setters and getters

    I would like to break my app down into more java classes but not sure how to do this.

    In my main class ( imgGameBoard[x] ) "is a large array of Image View's"

    GameBoardClass.imgGameBoard[x].setImageDrawable(getResources().getDrawable(R.dra wable.cat_picture));

    I would like to use this in my other java classes but don't know how

    something like this
    ImageView img[];
    for (int x = 0; x < GameBoardClass.imgGameBoard.length; x++){
    img[x]= GameBoardClass.imgGameBoard[x];

    }
    img[x].setImageDrawable(getResources().getDrawable(R.dra wable.cat_picture));

    any basic example of this working would be great

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to use getResources() in setters and getters

    don't know how
    Have you tried coding it?
    What happens when you try it?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2019
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: how to use getResources() in setters and getters

    All the code works but " (getResources()."
    As its in red and needs some code in the bracket
    To use the active.Imageview findview.by.id( main class ) in a second class

    If I can't work it out I will use fragments as there built for this

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to use getResources() in setters and getters

    (getResources()."
    As its in red
    Do you get a compiler error message that says what is wrong?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Setters and getters
    By maths94 in forum What's Wrong With My Code?
    Replies: 33
    Last Post: December 11th, 2013, 08:28 PM
  2. help with setters and getters
    By takira in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 28th, 2013, 12:34 PM
  3. help with setters and getters
    By takira in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 26th, 2013, 04:10 PM
  4. Can anyone explain the Getters and setters in Java
    By sivasubramaniam in forum Java Theory & Questions
    Replies: 4
    Last Post: July 30th, 2013, 06:47 AM
  5. Encapsulation (getters and setters) Tips?
    By Robertgif in forum Java Theory & Questions
    Replies: 4
    Last Post: March 2nd, 2013, 06:36 AM