try/catch ispred konstruktora?
31.05.2008. u 16:20 · pre 223 meseci
#1
Poz,
Metod getResource(fileName) baca NullPointerException ako datoteka nije pronadjena, a ja ne mogu da koristim try/catch blok ispred konstruktora izgleda. Kako da resim ovaj problem?
Hvala unapred
H
Code:
class Book {
public static final ImageIcon DEGREE1 = new ImageIcon(Book.class.getResource("slike/degree1.png"));
public static final ImageIcon DEGREE2 = new ImageIcon(Book.class.getResource("slike/degree2.png"));
public static final ImageIcon DEGREE3 = new ImageIcon(Book.class.getResource("slike/degree3.png"));
public static final ImageIcon DEGREE4 = new ImageIcon(Book.class.getResource("slike/degree4.png"));
public static final ImageIcon DEGREE5 = new ImageIcon(Book.class.getResource("slike/degree5.png"));
...etc...
}
class Book {
public static final ImageIcon DEGREE1 = new ImageIcon(Book.class.getResource("slike/degree1.png"));
public static final ImageIcon DEGREE2 = new ImageIcon(Book.class.getResource("slike/degree2.png"));
public static final ImageIcon DEGREE3 = new ImageIcon(Book.class.getResource("slike/degree3.png"));
public static final ImageIcon DEGREE4 = new ImageIcon(Book.class.getResource("slike/degree4.png"));
public static final ImageIcon DEGREE5 = new ImageIcon(Book.class.getResource("slike/degree5.png"));
...etc...
}
Metod getResource(fileName) baca NullPointerException ako datoteka nije pronadjena, a ja ne mogu da koristim try/catch blok ispred konstruktora izgleda. Kako da resim ovaj problem?
Hvala unapred
H
Potpis
i5-750 @4GHz with CM Hyper 212+
GTX 580 Lightning XE 3GB
Corsair HX750
CM Sniper
GTX 580 Lightning XE 3GB
Corsair HX750
CM Sniper
Re: try/catch ispred konstruktora?