Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Hey I have a panel that contains a label that i have to change it's icon everythime i click on a button ( there are 2 buttons here activate and disactivate ) .and these 2 images that i want to set as icons are in my ressources under a backage called "imgs". Example : imgs/img_x.png so who to change that icon ? cause i always get a null pointer exception. i need that in java not in Android Thanks

Icon c=new ImageIcon(getClass().getResource("src/imgs/img_not_activated.png"));
        img_etat_pharmacie.setIcon(c);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
243 views
Welcome To Ask or Share your Answers For Others

1 Answer

Images don't go in the src folder.
Save them under res/drawable; Then access them like:

    Drawable dr = getResources().getDrawable(R.drawable.arrow);

Please see the resource part of this tutorial.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...