【发布时间】:2019-11-15 04:23:51
【问题描述】:
这段代码在 for 循环中的 Image.createImage(path) 上给了我一个 NullPointerException。
怎么可能?
我使用一个数组作为名称,一个作为路径,一个ArrayList 作为按钮。
private final String[] IMG_MENU = {"/timbratura.png", "/archivio.png", "/nota_spese.png"};
private final String[] LABEL_BOTTONI_HOME = {"Timbratura", "Archivio", "Nota spese"};
private ArrayList<Button> bottoni = new ArrayList<>();
我创建了一些按钮,将图标设置为生成的图像并将其添加到ArrayList。
for(int i = 0; i < LABEL_BOTTONI_HOME.length; i++) {
Button b = new Button(LABEL_BOTTONI_HOME[i]);
try {
Image im = Image.createImage(IMG_MENU[i]);
im = im.scaled(screen_width/100*20, screen_width/100*20);
b.setIcon(im);
} catch (IOException ex) {
Log.e(ex);
}
bottoni.add(b);
}
【问题讨论】:
标签: ios codenameone picker