Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

java - Access to resources (images) inside jars/classpath

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...