java - Trouble Importing Resources with Eclipse -
i'm setting jlabel show icon.
public icon geticon(string type) throws ioexception { string avatar = "academic.jpg"; switch(type) { case"academic": avatar ="academic.jpg"; break; case"alchemist": avatar ="alchemist.jpg"; break; case"assassin": avatar ="assassin.jpg"; break; } classloader classloader = thread.currentthread().getcontextclassloader(); inputstream input = classloader.getresourceasstream(avatar); image logo = imageio.read(input); icon icon = new imageicon(logo); return icon; }
"input" still null on 3rd line, when "avatar" contains string "pic.jpg". resources folder in src folder? have done wrong? how eclipse know how find images?
you passing file name no path of kind unless file located @ root of project, , or classpath not found. need add path details of file located. sounds @ least start with:
/src/resources//academic.jpg
Comments
Post a Comment