Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: image does not load to .jar file after been compile

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Thanked 0 Times in 0 Posts

    Default image does not load to .jar file after been compile

    Hi, i have create a game call Ninjabomb.The game we work fine in compiler but when i compile into .jar, only empty jframe appears.Here i attach my image code
    import java.awt.Component;
    import java.awt.MediaTracker;
    import java.awt.image.BufferedImage;
    public class roleImageArray {
        MediaTracker _mt;
        BufferedImage _back[];
        BufferedImage _fire[];
        BufferedImage _play[];
        BufferedImage _playStart;
        BufferedImage _foemans[];
        BufferedImage _end[];
        BufferedImage _foemansNow;
        BufferedImage _bonus[];
        BufferedImage _bom;
        BufferedImage _bomb;
        BufferedImage _ray;
        BufferedImage _charred;
        BufferedImage _greatman;
        BufferedImage _greatman_bomb;
        public roleImageArray(Component canvas) {
            _back = new BufferedImage[6];
            _fire = new BufferedImage[5];
            _play = new BufferedImage[6];
            _foemans = new BufferedImage[20];
            _bonus = new BufferedImage[3];
            _bonus[0] = ImageUtils.loadImage("item_fire.png");
            _bonus[1] = ImageUtils.loadImage("item_bomb.png");
            _bonus[2] = ImageUtils.loadImage("item_greatman.png");
            _end = new BufferedImage[2];
            _end[0] = ImageUtils.loadImage("win.jpg");
            _end[1] = ImageUtils.loadImage("gameover.jpg");
            _back[0] = ImageUtils.loadImage("rock.png");
            _back[1] = ImageUtils.loadImage("wall.png");
            for (int i = 0; i < _fire.length; i++) {
                _fire[i] = ImageUtils.loadImage("fire.png");
            _play[0] = ImageUtils.loadImage("player0.png");
            _play[1] = ImageUtils.loadImage("player1.png");
            _play[2] = ImageUtils.loadImage("player2.png");
            _play[3] = ImageUtils.loadImage("player3.png");
            _play[4] = ImageUtils.loadImage("player4.png");
            _play[5] = ImageUtils.loadImage("player5.png");
            _greatman = ImageUtils.loadImage("greatman.png");
            _greatman_bomb = ImageUtils.loadImage("greatman_bomb.png");
            _foemans[0] = ImageUtils.loadImage("beast0.png");
            _foemans[1] = ImageUtils.loadImage("beast1.png");
            _foemans[2] = ImageUtils.loadImage("beast2.png");
            _foemans[3] = ImageUtils.loadImage("beast3.png");
            _foemans[4] = ImageUtils.loadImage("beast4.png");
            _foemans[5] = ImageUtils.loadImage("beast5.png");
            _foemans[6] = ImageUtils.loadImage("beast6.png");
            _foemans[7] = ImageUtils.loadImage("beast7.png");
            _foemans[9] = ImageUtils.loadImage("beast9.png");
            _foemans[8] = ImageUtils.loadImage("beast8.png");
            _foemans[10] = ImageUtils.loadImage("beast10.png");
            _foemans[11] = ImageUtils.loadImage("beast11.png");
            _foemans[12] = ImageUtils.loadImage("beast12.png");
            _foemans[13] = ImageUtils.loadImage("beast13.png");
            _foemans[14] = ImageUtils.loadImage("beast14.png");
    //		_foemans[12] = ImageUtils.loadImage("beast12.png");
            _bom = ImageUtils.loadImage("boom.png");
            _bomb = ImageUtils.loadImage("bomb.png");
            _ray = ImageUtils.loadImage("ray.png");
            _charred = ImageUtils.loadImage("charred.png");
            _mt = new MediaTracker(canvas);
            _mt.addImage(_end[0], 1);
            _mt.addImage(_end[1], 1);
            _mt.addImage(_back[0], 1);
            _mt.addImage(_back[1], 1);
            _mt.addImage(_playStart, 1);
            _mt.addImage(_foemans[1], 1);
            _mt.addImage(_bom, 1);
            _mt.addImage(_bomb, 1);
        public BufferedImage[] getEnd() {
            return _end;
        public BufferedImage[] getBack() {
            return _back;
        public void setBack(BufferedImage[] back) {
            this._back = back;
        public BufferedImage getBomb() {
            return _bomb;
        public BufferedImage getRay() {
            return _ray;
        public BufferedImage getCharred() {
            return _charred;
        public void setBakuha(BufferedImage bomb) {
            this._bomb = bomb;
        public BufferedImage getBom() {
            return _bom;
        public void setBom(BufferedImage bom) {
            _bom = bom;
        public BufferedImage[] getFire() {
            return _fire;
        public BufferedImage getGreatman() {
            return _greatman;
        public BufferedImage getGreatman_bomb() {
            return _greatman_bomb;
        public void setFire(BufferedImage[] fire) {
            this._fire = fire;
        public BufferedImage[] getBonus() {
            return _bonus;
        public void setBonus(BufferedImage[] bonus) {
            _bonus = bonus;
        public BufferedImage[] getFoemans() {
            return _foemans;
        public void setFoemans(BufferedImage[] foemans) {
            this._foemans = foemans;
        public BufferedImage getFoemansNow() {
            return _foemansNow;
        public void setFoemansNow(BufferedImage foemansNow) {
            this._foemansNow = foemansNow;
        public MediaTracker getMt() {
            return _mt;
        public void setMt(MediaTracker mt) {
            this._mt = mt;
        public BufferedImage[] getPlay() {
            return _play;
        public void setPlay(BufferedImage[] play) {
            this._play = play;
        public BufferedImage getPlayStart() {
            return _playStart;
        public void setPlayStart(BufferedImage playStart) {
            this._playStart = playStart;

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,460 Times in 2,411 Posts

    Default Re: image does not load to .jar file after been compile

    Where does the ImageUtils class's methods look for the image files?
    Its better if the images are put in the jar file and treated as resources instead of files. Resources in jar files are accessed via getResource methods that return a URL or stream for reading the resource.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Urgent! How to compile a whole library to Jar
    By JavaCup in forum Java Theory & Questions
    Replies: 2
    Last Post: May 11th, 2012, 11:46 AM
  2. how to show/open/load JPanel(form) in an external jar
    By iskandar in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 16th, 2012, 07:19 AM
  3. [SOLVED] Picture won't go with the .jar (Wrong code or compile error?)
    By Fermen in forum Object Oriented Programming
    Replies: 3
    Last Post: March 15th, 2011, 05:22 PM
  4. Image Load
    By shadihrr in forum Java Theory & Questions
    Replies: 4
    Last Post: August 26th, 2010, 06:56 AM
  5. Image location on a Runnable JAR file?
    By DarrenReeder in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 11th, 2010, 07:59 AM