Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Help: Unable to load image  (Read 1076 times)
0 Members and 1 Guest are viewing this topic.
Offline thelordofcheese

Junior Newbie




Java games rock!


« Posted 2005-01-21 16:48:59 »

i'm trying to add a splash screen to a small java game i wrote, and i'm using the following code to get the file

1  
image = Image.createImage ("/splash.png");



Now the file is located in the same directory as the source code, and isn't set to read-only or anything.

yet i get a IO exception when i try and run the midlet

it claims it cannot load the  image.
Am i missing file permissions for the image, or is it even in the right place?

Thanks in advance for your help


Offline calzada

Junior Member




m3g is the truth


« Reply #1 - Posted 2005-01-21 19:07:16 »

send us the EX

Mobile Entertainment Studio: M-E-S
http://sourceforge.net/projects/cazapool3d/
Offline wooD

Senior Newbie




J2ME Developer


« Reply #2 - Posted 2005-01-21 19:47:58 »

Make sure the image is actually in the jar file using the command.

jar -tvf filename.jar

if you are using the SunWtk then the image needs to be placed in the res directory, not the src directory. if you are using netbeans, then I'm pretty sure the image can be in the src directory. I only use netbeans to develop, for my final jars, i use sunwtk.

Wood

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline thelordofcheese

Junior Newbie




Java games rock!


« Reply #3 - Posted 2005-01-22 18:48:49 »

ok, i'm using Ktoolbar to build the game, then running it from the command line with midp -classpath . filename

[i don't have net access at home, so the RUN button just doesn't work]

I've built the Jad and .Jar files and the splash.png is included.

yet no matter where i place the image file [in the rec  or src folders, it matters not] i still get the IO Exception


For the sake of it, this is the Splash.java code i'm using

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
import javax.microedition.lcdui.*;

public class splash extends Canvas implements Runnable

{
   private boolean running = true;
   private Image osb;
   private Graphics osg;
   private Blockade theMidlet;
   private int starFieldViewY;
   private Image title;
   private int fontHeight;
   private Font font;
   private String filename;
   
   
   public splash(Blockade midlet)
   {
      theMidlet = midlet;
      initResources();

      // create the timer thread
     Thread t = new Thread(this);
      t.start();
   }

   private void initResources()
   {
      // setup the screen
     
      try
      {
      osb = Image.createImage(getWidth(), getHeight());
      osg = osb.getGraphics();

   
     
       filename =  "/splash.png";
     
       title = Image.createImage(filename);
     
      font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
      fontHeight = font.getHeight() + 2;

      osg.setFont(font);
          }
          catch(Exception e)
          {
             
          System.out.println("can't load file: " + filename + " why? ==> " + e);
         e.printStackTrace();  
          }
         
   }

   private static final int MAX_CPS = 100;
   private static final int MS_PER_FRAME = 1000 / MAX_CPS;

   public void run()
   {
      try
      {
         while (running)
         {
            // remember the starting time
           long cycleStartTime = System.currentTimeMillis();

            // do our work
           repaint();

            // sleep if we've finished our work early
           long timeSinceStart = (cycleStartTime - System.currentTimeMillis());
            if (timeSinceStart < MS_PER_FRAME)
            {
               try
               {
                  Thread.sleep(MS_PER_FRAME - timeSinceStart);
               }
               catch (java.lang.InterruptedException e)
               {
               }
            }
         }

         // fall back to the splash form at the end of our loop
        theMidlet.activateMenu();
      }
      catch (Exception e)
      {
         System.out.println("App exception2: " + e);
         e.printStackTrace();
      }

   }

   private void renderSplash()
   {
      // clear the background
     osg.setColor(0);
      osg.fillRect(0, 0, getWidth(), getHeight());

     

      osg.drawImage(title, getWidth() / 2, getHeight() / 2 - 10, Graphics.HCENTER | Graphics.VCENTER);

      // draw text
     osg.setColor(0x00888888);
      osg.drawString("© 2005", getWidth() / 2, getHeight() - fontHeight * 3,
                     Graphics.HCENTER | Graphics.TOP);
      osg.drawString(" Crontastic Production", getWidth() / 2, getHeight() - fontHeight * 2,
                     Graphics.HCENTER | Graphics.TOP);
      // draw the copy line
     osg.setColor(0x00ffffff);
      osg.drawString("Press Any Key", getWidth() / 2, getHeight() - fontHeight * 1,
                     Graphics.HCENTER | Graphics.TOP);
   }

   protected void paint(Graphics graphics)
   {
      renderSplash();
      graphics.drawImage(osb, 0, 0, Graphics.LEFT | Graphics.TOP);
   }

   protected void keyPressed(int keyCode)
   {
      running = false;
   }

   

}
Offline wooD

Senior Newbie




J2ME Developer


« Reply #4 - Posted 2005-01-24 13:48:51 »

The code looks fine to me. My guess would be a case sensitive file name?  Maybe your file is named title.PNG or something like that? I'm pretty sure J2ME is case sensitive with file names, I know J2SE is, but I'm very careful to always use lowercase so I have never tested or cared to look it up.

If the case is correct, I think it would be helpful to see the jar -tvf output posted here.

Wood

Offline thelordofcheese

Junior Newbie




Java games rock!


« Reply #5 - Posted 2005-01-24 14:14:19 »

I finally got it to work, i don't know why or how this works, but i copied the splash.png file into every directory in the folder.
the classes, bin, lib src folders, all of them,  and now it works. I'm sure that i've put it into more folder than is nessicary, but i'll fix that through trial and error later.
but it works.

Or  be more correct it doesn't give me an IOException anymore.

on the downside it now displays an empty screen.... so the code is probably b0rked somewhere.

Arse.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (75 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!