Bonjour,
Pour faciliter la gestion d'éléments de mon Canvas graphique, j'ai créé un tout bête (pour l'instant) constructeur SvgImage.
Bien que je ne pense avoir rien oublié, mon code génère une NullPointerException lors du rendu.
Comme je n'ai rien changé d'autre que mon constructeur et qu'avant cela, mon script ne retournait pas d'erreur, j'imagine qu'il doit en être la cause mais je ne vois pas en quoi.
Pourriez-vous m'éclairer, svp?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 import java.io.IOException; import java.io.InputStream; import javax.microedition.lcdui.*; import javax.microedition.m2g.SVGAnimator; import javax.microedition.m2g.SVGEventListener; import javax.microedition.m2g.SVGImage; import javax.microedition.m2g.ScalableGraphics; import javax.microedition.midlet.*; import org.w3c.dom.*; import org.w3c.dom.svg.*; public class MyApp extends MIDlet{ private SvgCanvas canvas; public MyApp(){ } public void startApp(){ canvas=new SvgCanvas("logo",this); Display.getDisplay(this).setCurrent(canvas); } public void pauseApp(){ } public void destroyApp(boolean unconditional){ } } class SvgCanvas extends Canvas{ protected SvgImage svgImage; protected ScalableGraphics sg=ScalableGraphics.createInstance(); private static String img; private static MIDlet midlet; public SvgCanvas(String img,MIDlet midlet){ this.setFullScreenMode(true); this.img=img; this.midlet=midlet; } public void paint(Graphics g){ sg.setRenderingQuality(2); g.setColor(219,238,255); g.fillRect(0,0,getWidth(),getHeight()); sg.bindTarget(g); svgImage=new SvgImage(img); svgImage.setViewportWidth(getWidth()); svgImage.setViewportHeight(getHeight()); sg.render(0,0,svgImage); sg.releaseTarget(); } } class SvgImage extends SVGImage{ public SvgImage(String img){ try{ this.createImage((InputStream)getClass().getResourceAsStream("/"+img+".svg"),null); } catch(Exception e){ } } }
Partager