Results 1 to 6 of 6
Thread: ImageIcon problem
- 02-24-2012, 05:36 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 9
- Rep Power
- 0
ImageIcon problem
Basiclly for now my goal is a drop down list which shows pictures depending on what is selected.
Errors at:Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GUI extends JFrame{ private JLabel ProfilePicture; private JComboBox HeroNames; private static String[] Heroes = {"Alchemist", "Ancient_Apparition", "Anti-Mage", "Axe", "Beastmaster", "Bloodseeker", "Bounty_Hunter", "Broodmother", "Chen", "Clinkz", "Clockwerk", "Crystal_Maiden", "Dark_Seer", "Dazzle", "Death_Prophet", "Doom_Bringer", "Dragon_Knight", "Drow_Ranger", "Earthshaker", "Enchantress", "Enigma", "Faceless_Void", "Huskar", "Invoker", "Jakiro", "Juggernaut", "Kunkka", "Leshrac", "Lich", "Lifestealer", "Lina", "Lion", "Mirana", "Morphling", "Nature's_Prophet", "Necrolyte", "Night_Stalker", "Omniknight", "Outworld_Destroyer", "Puck", "Pudge", "Queen_Of_Pain", "Razor", "Riki", "Sand_King", "Shadow_Fiend", "Shadow_Shaman", "Silencer", "Skeleton_King", "Slardar", "Sniper", "Spectre", "Spirit_Breaker", "Storm_Spirit", "Sven", "Tidehunter", "Tiny", "Tinker", "Ursa", "Vengeful_Spirit", "Venomancer", "Viper", "Warlock", "Weaver", "Windrunner", "Witch_Doctor", "Zeus"}; private Icon[] pics; public GUI(){ super("Dota 2 Helper"); for(int i = 0; i < 67 ; i++){ pics[i] = new ImageIcon(getClass().getResource(Heroes[i]+".png")); } setLayout(new FlowLayout()); HeroNames = new JComboBox(Heroes); HeroNames.addItemListener( new ItemListener(){ public void itemStateChanged(ItemEvent event){ if(event.getStateChange()==ItemEvent.SELECTED) ProfilePicture.setIcon(pics[HeroNames.getSelectedIndex()]); } } ); add(HeroNames); ProfilePicture = new JLabel(pics[0]); add(ProfilePicture); } }
pics[i] = new ImageIcon(getClass().getResource(Heroes[i]+".png"));
ProfilePicture = new JLabel(pics[0]);
add(ProfilePicture);
These might be related though
-
Re: ImageIcon problem
You mention "Errors at:..." but neglect to post the error message. That kind of is important information.
- 02-24-2012, 06:25 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 9
- Rep Power
- 0
Re: ImageIcon problem
Exception in thread "main" java.lang.NullPointerException
at GUI.<init>(GUI.java:59)
at Main.main(Main.java:5)
main 5 is calling the class
-
Re: ImageIcon problem
You will need to instantiate the pics array before using it. i.e.,
Java Code:private Icon[] pics = new Icon[someNumberGoesHere];
- 02-24-2012, 06:37 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 9
- Rep Power
- 0
Re: ImageIcon problem
*cries tears of joy*
Thank you so much, good sir!
-
Similar Threads
-
BufferedImage to ImageIcon
By han003 in forum New To JavaReplies: 2Last Post: 03-25-2011, 11:13 AM -
Need help with ImageIcon and int
By proceeded in forum New To JavaReplies: 9Last Post: 01-23-2011, 10:10 PM -
ImageIcon Transparency
By Lingerz in forum New To JavaReplies: 2Last Post: 06-04-2010, 02:53 PM -
ImageIcon HELP!
By ben1989 in forum New To JavaReplies: 1Last Post: 05-05-2010, 08:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks