why isnt the image drawn?

im trying to create a game but i have a problem,the images are not drawn.

here is the code

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
import java.io.*;

/**
 *
 * @author  omashhour
 * @version
 */
public class slime extends MIDlet implements CommandListener{
    private Command exitCommand; // The exit command
    Display display;
    gamecore gc;    
   
    public slime(){
        display = Display.getDisplay(this);
        exitCommand = new Command("Exit", Command.SCREEN, 2);
       
        gc=new gamecore();
    }
    public void startApp() {
       
        display.setCurrent(gc);
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }
   
    public void commandAction(Command c, Displayable s) {
        if (c == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
}

class gamecore extends Canvas implements Runnable{
   
    Thread thread;
    Image offImage;
    Graphics og;
    Player p;

    public gamecore(){
       
        p=new Player();
       
        thread=new Thread();
        thread.start();
       
       
       
    }
   
     public void paint(Graphics g) {
        if(og==null){
            offImage=Image.createImage(getWidth(),getHeight());
            og=offImage.getGraphics();
        }
        p.draw(og);
        g.drawImage(offImage,0,0,Graphics.TOP|Graphics.LEFT);

     }
     
     public void run(){
         while(true){
           
            try{
                thread.sleep(20);
            }
            catch(Exception e){
            }
            repaint();
         }
         
     }
     
}

class Player extends gamecore{
   
    Image player;
   
    public Player(){
        player=loadimage("/gondy.png");
    }
   
    public Image loadimage(String file){
        Image image=null;
        try{
            image=Image.createImage(file);
        }
        catch(Exception e){
        }
        return image;
    }
   
    public void draw(Graphics g){
        g.drawImage(player,30,30,Graphics.TOP|Graphics.LEFT);        
    }
   
}
LVL 1
omashhourAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nesnemisCommented:
Hi omashhour,

maybe you should check if you get an exception, file not found or something.
 
try{
            image=Image.createImage(file);
        }
        catch(Exception e){
                //check if any exception
                System.out.println(e.getMessage());
        }


nesnemis
0
petmagdyCommented:
Hi omashhour,

where is the png file inside ur J2ME application jar?

Cheers!
0
petmagdyCommented:
aaahhhh, in ur midlet

>>         gc=new gamecore();
it should be :

gc = new Player();
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

omashhourAuthor Commented:
i get no exception  and the i tried gc =new player(); it didnt work.
btw i will make another class called cpu  it will also have a draw method ,so i think both draw methods in cpu ad player should be called in the draw method inside gamecore, but i dont know how
0
petmagdyCommented:
u didn't answer my question:

>> where is the png file inside ur J2ME application jar?

usually u put the images inside a directory from the code root called res

and call like this
loadimage("/res/gondy.png");


also please try on Player class and don't make Player class extends game core for testing purpose
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
omashhourAuthor Commented:
the image is in the same folder as the java file i still didnt create a jar file
0
omashhourAuthor Commented:
thanks it worked when i didnt extend the class :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.