java - Error while loading image -


यह मेरा कोड है:

  आयात करें java.awt.image.BufferedImage; आयात करें java.io.File; आयात java.io.IOException; आयात javax.imageio। *; आयात javax.swing.ImageIcon; आयात javax.swing.JLabel; आयात मॉडल। मैप; सार्वजनिक वर्ग MyView {निजी BufferedImage img = null; निजी स्थिर MyPanel पैनल; // init छवि {img = imageIO.read (नई फ़ाइल ("/ src / minepic / start.png") का प्रयास करें); } पकड़ (IOException ई) {System.out.println (e.getMessage ()); }}   

मुझे src निर्देशिका से पीएनजी छवि लोड करना है, लेकिन मुझे नहीं पता कि यह क्यों काम नहीं करता है, कोई भी मेरी मदद कर सकता है?

त्रुटि कमांड में "पकड़ने की कोशिश करो" और नेटबैंस का कहना है कि "अपरिवर्तित अपवाद IOexception; पकड़े जाने या घोषित करने के लिए घोषित किया जाना चाहिए" एक और भी, मैंने भी पहले एक बफर्ड इमेज के रूप में आईएमजी को घोषित किया है, लेकिन कमांड में "पकड़ने की कोशिश" आईएमजी की तरह ही घोषित नहीं किया गया क्योंकि NetBeans में यह हरे, फिर भी काला नहीं बनता है।

कोड के साथ कुछ समस्याएं हैं: < / P>

  1. यह अधूरा है
  2. आपने मुख्य विधि के बाहर कोड लिखा है (संभावित लेकिन अनुशंसित नहीं)
  3. स्रोत फ़ोल्डर से छवि को पढ़ने के लिए (जो कि आपका एक हिस्सा है वर्ग पथ) नीचे दिए गए स्निपेट का उपयोग करें:

      Inputstream = MyView.class.getResourceAsStream ("minepic / start.png"); अगर (है == नल) {है = MyView.class.getClassLoader ()। GetResourceAsStream ("माइनल / प्रारंभ पेज"); } Img = ImageIO.read (है);      

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -