Skip to content
Advertisement

Codename One images not loading

The image(s) is in the “src” folder. Everything was working fine, until this morning I keep getting a black screen when I run the simulator with “java.lang.IllegalArgumentException: stream == null!”

import com.codename1.system.Lifecycle;
import com.codename1.ui.Form;
import com.codename1.ui.Image;
import com.codename1.ui.Label;
import com.codename1.ui.layouts.BoxLayout;

import java.io.IOException;

public class Application extends Lifecycle {
    @Override
    public void runApp() {
        Image image = null;
        try {
            image = Image.createImage("/icon.png");
        } catch (IOException e) {}
        Label label = new Label();
        label.setIcon(image);
        Form form = new Form(BoxLayout.yCenter());
        form.setLayout(BoxLayout.xCenter());
        form.add(label);
        form.show();
    }
}

Advertisement

Answer

You can’t let the exception bubble since the method is a callback and this is a checked exception. But add Log.e(e) into the catch block. NEVER do a blank catch block.

If you use Maven the image needs to be in the resources directory not in the src directory. Like you see here in the KitchenSink. Under common/src/main/resources.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement