View Single Post
Old 09-10-2011, 12:45 AM   #1
liuto
Connoisseur
liuto is on a distinguished road
 
Posts: 50
Karma: 70
Join Date: Nov 2010
Device: Kindle DXG / Kindle 3
Load image from jar file

Hi,

Could anyone help me to figure out why this code just get Kindle show me 'An error occurred openning the title'?

I just try to load a png image in my Kindlet. looks like it get error on 'Create' method.


Code:
package kapp;

import com.amazon.kindle.kindlet.AbstractKindlet;
import com.amazon.kindle.kindlet.KindletContext;
import com.amazon.kindle.kindlet.ui.KImage;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;

public class Main extends AbstractKindlet {

    private KindletContext ctx;
    private Image im;
    private KImage card;

    public void create(KindletContext context) {
        this.ctx = context;

        URL urlImage = getClass().getResource("Images/xxx.png");
        this.im = Toolkit.getDefaultToolkit().createImage(urlImage);        
        this.card = new KImage (im);

        try {
            ctx.getRootContainer().add(this.card);
        } catch (Throwable t) {
            //ctx.getRootContainer().
            //t.printStackTrace();
        }
    }

    public void start() {
        try {
            //this.card.setBounds(256, 56, 75, 108);
        } catch (Throwable ex) {
            //ex.printStackTrace();
        }
    }

    public void stop() {
    }

}
By move the 'try' statment, I can identify this line causes the error:

Code:
           this.im = Toolkit.getDefaultToolkit().createImage(urlImage);
but I don't know why......

Last edited by liuto; 09-10-2011 at 12:56 AM.
liuto is offline   Reply With Quote