Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 12-06-2013, 11:05 AM   #1
dragon123
Junior Member
dragon123 began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Dec 2013
Device: kindle 4
Loading a png file

Hi,

could anyone help me to figure out why nothing is happen when I'm trying to load a png file in my kindlet. The kindlet is starting, but neither the picture is shown nor an error is saved in the crash log. I don't know why. Could anyone help me please.

Code:
package kindlebeispiel;

import com.amazon.kindle.kindlet.AbstractKindlet;
import com.amazon.kindle.kindlet.KindletContext;
import com.amazon.kindle.kindlet.ui.KImage;
import com.amazon.kindle.kindlet.ui.KTextArea;
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("/weather-icons/mix.png");
        this.im = Toolkit.getDefaultToolkit().createImage(urlImage);        
        this.card = new KImage(im);
    }

    public void start() {
        try {
            //ctx.getRootContainer().add(new KTextArea("Hello World!"));
            ctx.getRootContainer().add(this.card);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    public void stop() {
    }

    public void destroy() {
    }
}
dragon123 is offline   Reply With Quote
Old 12-06-2013, 12:22 PM   #2
ixtab
(offline)
ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.
 
ixtab's Avatar
 
Posts: 2,907
Karma: 6736092
Join Date: Dec 2011
Device: K3, K4, K5, KPW, KPW2
I'm writing this blindly (without access to a Kindle), so I can't really judge whether I'm wrong or right. I also don't know what the problem is, but here are some thoughts, in the order of complexity.

1. Make sure that your image is actually present in the .azw2 file where you expect it to be.

2. Avoid "absolute" paths in resources. Whenever I have to deal with resources, I tend to create a subpackage where the resources are, along with a class to load them using their relative names. Something like this:
Code:
package resources
class Resources {
  public static URL load(String name) {
    return Resources.class.getResource(name)
  }
}

// main code:
// mix.png is looked for in the "logical" package resources.icons
URL url = Resources.load("icons/mix.png")
So in essence, make sure that you're actually getting a URL, not null. Maybe something is smart enough to not throw exceptions on null input (though I doubt it).

3. Finally, it could be that the image is not fully loaded yet. I'm not sure if/when this really happens, but anyway here's a snippet of code that works on the K5. Look on line 184 for the actual magic. And don't ask me why that works

4. Of course, I assume that your application is otherwise working and displaying correctly (except for the image). Another hint: I always find it useful to have some kind of "status" text where I can programmatically show stuff (like, the URL in your case). You could simply use your existing text area for that.

5. You'd have to refactor your code a bit for the above to work (putting the image loading in start() instead of create()), but that's a VERY good idea anyway. The create() method should do as little logic as possible, because Kindles aren't exactly fast, and you have a maximum of 5000 ms for creation. Make sure that you took a look at the online documentation for AbstractKindlet though (especially the lifecycle diagram!) because start() can be called multiple times, IIRC.


HTH and good luck
ixtab is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Books loading into document file Mumgod Kindle Fire 14 02-07-2012 05:37 AM
Sigil not responding 100% CPU usage when loading a 38 MB epub file leo315 Sigil 3 02-17-2011 05:01 AM
iPad 60MB PDF file is loading nothing but white pages Philippe Lemay Apple Devices 5 09-03-2010 03:07 AM
where to get autorun.xml, icon.png, key.png, lut.bin for PRS-505 obender Sony Reader Dev Corner 2 01-25-2009 03:20 PM
Large sony file not loading markiehill Sony Reader 3 10-10-2008 12:10 PM


All times are GMT -4. The time now is 08:11 AM.


MobileRead.com is a privately owned, operated and funded community.