You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Mathieu Pedrero <ma...@centraliens-lille.org> on 2009/08/20 11:18:43 UTC

Appending a child (animateColor) to an element!

Hi everybody !

I've got a little problem when I try to ad an animateColor element to
an existing element in my document: I've got a NullPointerException
thrown:


Can you help me, please, to find the mistake? I dont see what could be
the problem (nothing is null in the appendChild method I call...) ! I
often add nodes to documents in my projects, and it's the first time i
had to face this kind of error.

Let's see my code :

################################################
The code
################################################

public void run(){

        System.out.println("BLINK lancé");
        Element element =
this.document.getElementById("button_"+this.iD), child;
        if (this.color1==null){

            //Treantments if the color1 field of my thread is null
(code missing in order to read my program more easily: here is not the
problem)

            }
        } else{

            //Declaration and initialization of the strings red1 red2,
green1, green2, blue1, blue2 (code missing in order to read my program
more easily: here is not the problem)


            // Creation and initialization of the animateColor
elements (following code)

            Element toColor2 =
this.document.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI,"animateColor"),
toColor1 = this.document.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI,"animateColor");
            toColor2.setAttributeNS(null, "id","blink2");
            toColor2.setAttributeNS(null, "attributeName","fill");
            toColor2.setAttributeNS(null, "attributeType","XML");
            toColor2.setAttributeNS(null, "from", "#"+red1+green1+blue1);
            toColor2.setAttributeNS(null, "to", "#"+red2+green2+blue2);
            toColor2.setAttributeNS(null, "begin", "0s;blink1.end");
            toColor2.setAttributeNS(null, "dur", "0.5s");
            toColor1.setAttributeNS(null, "id","blink1");
            toColor1.setAttributeNS(null, "attributeName","fill");
            toColor1.setAttributeNS(null, "attributeType","XML");
            toColor1.setAttributeNS(null, "to", "#"+red1+green1+blue1);
            toColor1.setAttributeNS(null, "from", "#"+red2+green2+blue2);
            toColor1.setAttributeNS(null, "begin", "blink2.end");
            toColor1.setAttributeNS(null, "dur", "0.5s");

            //The two following lines show me that neither element or toColor2
            System.out.println("Element: "+element);
            System.out.println(toColor2);

            //The following line reports the exception
            element.appendChild(toColor2);


            element.appendChild(toColor1);
        }
    }

################################################
Here is the report of the exception
################################################

java.lang.NullPointerException
	at org.apache.batik.anim.timing.SyncbaseTimingSpecifier.<init>(SyncbaseTimingSpecifier.java:65)
	at org.apache.batik.anim.timing.TimingSpecifierListProducer.syncbase(TimingSpecifierListProducer.java:99)
	at org.apache.batik.parser.TimingSpecifierParser.handleTimingSpecifier(TimingSpecifierParser.java:90)
	at org.apache.batik.parser.TimingSpecifierListParser.doParse(TimingSpecifierListParser.java:74)
	at org.apache.batik.parser.AbstractParser.parse(AbstractParser.java:150)
	at org.apache.batik.anim.timing.TimingSpecifierListProducer.parseTimingSpecifierList(TimingSpecifierListProducer.java:79)
	at org.apache.batik.anim.timing.TimedElement.parseBegin(TimedElement.java:1097)
	at org.apache.batik.anim.timing.TimedElement.parseAttributes(TimedElement.java:1072)
	at org.apache.batik.bridge.SVGAnimationElementBridge.initializeTimedElement(SVGAnimationElementBridge.java:301)
	at org.apache.batik.bridge.SVGAnimationElementBridge.initializeTimedElement(SVGAnimationElementBridge.java:261)
	at org.apache.batik.bridge.SVGAnimationElementBridge.handleElement(SVGAnimationElementBridge.java:155)
	at org.apache.batik.bridge.AbstractGraphicsNodeBridge.handleDOMNodeInsertedEvent(AbstractGraphicsNodeBridge.java:284)
	at org.apache.batik.bridge.BridgeContext$DOMNodeInsertedEventListener.handleEvent(BridgeContext.java:1601)
	at org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:324)
	at org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:366)
	at org.apache.batik.dom.events.EventSupport.dispatchEvent(EventSupport.java:258)
	at org.apache.batik.dom.AbstractNode.dispatchEvent(AbstractNode.java:1014)
	at org.apache.batik.dom.AbstractParentNode.fireDOMNodeInsertedEvent(AbstractParentNode.java:422)
	at org.apache.batik.dom.AbstractParentNode.appendChild(AbstractParentNode.java:224)
	at src.threads.ThreadBlink.run(ThreadBlink.java:103)  => The
incriminated line in the code upper in this mail
	at org.apache.batik.util.RunnableQueue.run(RunnableQueue.java:237)
	at java.lang.Thread.run(Thread.java:636)


Can you help me, please, to find the mistake? I dont see what could be
the problem (nothing is null in the appendChild method I call...) ! I
often add nodes to documents in my projects, and it's the first time i
had to face this kind of error.

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Appending a child (animateColor) to an element!

Posted by Helder Magalhães <he...@gmail.com>.
Hi Mathieu,


> I gave very few informations about batik version (and so on) because i
> thought it was a mistake in my code (when I define the two
> animateColor nodes) ! If you think it may help:

I guess it generally always does, at least in the sense that one may
not be able to reproduce a given behavior and that may be due to a
version difference and/or platform-specific bug. ;-)


> So I work with batik 1.7, and the JDK 6, with a linux OS.

Without labeling version 1.7 "old", there were a handful of bug fixes
since the release. I'd say you should try a nightly build [1] or
compiling the latest source code [2]. :-)


> That's it! I want to make a blinking (is that the word for "clignoter"
> ?) effect on my document. I allready tried to do so by writing a svg
> document with a text editor, and it worked very well on Squiggle and
> Firefox.

I recall doing something like that (blinking effect) using a single
animation with 3 color values (initial, blink color, initial),
increasing the animation time coherently. A blinking effect can also
be achieved by animating opacity, for example... :-)


> I don't understand.

That text portion was repeated twice: one before the code snippet and
another after it. ;-)


Regards,
 Helder


[1] http://mcc.id.au/batik-nightly/
[2] http://xmlgraphics.apache.org/batik/download.cgi#Subversion+repository

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Appending a child (animateColor) to an element!

Posted by th...@kodak.com.
Hi Mathieu,

Mathieu Pedrero <ma...@gmail.com> wrote on 08/20/2009 01:41:31 
PM:

> I used this way of adding notes to documents, found in the "Scripting
> with Java", some times without any problem (but it was only for nodes
> as rect, circles, mask, clip-path). Here, the point is that for this
> animateColor node, i get a NullPointerException when i use the
> appendChild method.
> 
> >> Let's see my code :
> > [...]
> >>            toColor2.setAttributeNS(null, "id","blink2");
> >>            toColor2.setAttributeNS(null, "begin", "0s;blink1.end");
> >>            toColor1.setAttributeNS(null, "id","blink1");
> >>            toColor1.setAttributeNS(null, "begin", "blink2.end");

   So the problem is that when toColor2 is added the canvas can't resolve 
'blink1.end'.  I would have two suggestions to fix it. 
        1) Add both color element's to a group and then add the group to
         the document.  That way you should hopefully be able to resolve
         the circular references (I'm not 100% sure this will work).
        2) Reorder the code:

> >>            toColor2.setAttributeNS(null, "id","blink2");
> >>            toColor1.setAttributeNS(null, "id","blink1");

                blahBlah.appendChild(toColor1);
                blahBlah.appendChild(toColor2);

> >>            toColor2.setAttributeNS(null, "begin", "0s;blink1.end");
> >>            toColor1.setAttributeNS(null, "begin", "blink2.end");

     This avoids the issue of the document temporarily being "broken"
when the first color element is added.

Re: Appending a child (animateColor) to an element!

Posted by Mathieu Pedrero <ma...@gmail.com>.
Hi Helder!


2009/8/20 Helder Magalhães <he...@gmail.com>:
> Hi Mathieu,
>
>
> Note that you provide little information about Batik version being
> used (SVN checkout? Which revision number?). Also, you don't state
> whether you are following the instructions in "Scripting With Java"
> [1] (although you seem to, according to the "public void run(){" which
> I imagine it's a runnable implementation. Although it's a bit of
> overhead, please always try to state this, and other potentially
> useful information (Java version, operating system, etc.).
>
>

I gave very few informations about batik version (and so on) because i
thought it was a mistake in my code (when I define the two
animateColor nodes) ! If you think it may help:

So I work with batik 1.7, and the JDK 6, with a linux OS.

I work on the Netbeans IDE (5.0), but the project was created with NB 6.

I used this way of adding notes to documents, found in the "Scripting
with Java", some times without any problem (but it was only for nodes
as rect, circles, mask, clip-path). Here, the point is that for this
animateColor node, i get a NullPointerException when i use the
appendChild method.

>> Let's see my code :
> [...]
>>            toColor2.setAttributeNS(null, "id","blink2");
> [...]
>>            toColor2.setAttributeNS(null, "begin", "0s;blink1.end");
> [...]
>>            toColor1.setAttributeNS(null, "id","blink1");
> [...]
>>            toColor1.setAttributeNS(null, "begin", "blink2.end");
>
> Aren't the "blink#" in identifiers and SMIL begin creating a circular
> reference? I'd suggest you created a static SVG file (declaratively)
> in order to check if this works (if you create a sample file you'll be
> able to test not just Squiggle but also Opera, IE+ASV, Firefox nightly
> builds, etc.). ;-)
>

That's it! I want to make a blinking (is that the word for "clignoter"
?) effect on my document. I allready tried to do so by writing a svg
document with a text editor, and it worked very well on Squiggle and
Firefox.

>
>> Can you help me, please, to find the mistake? I dont see what could be
>> the problem (nothing is null in the appendChild method I call...) ! I
>> often add nodes to documents in my projects, and it's the first time i
>> had to face this kind of error.
>
> Twice? ;-)
>

I don't understand.

>
> Hope this helps,
>  Helder Magalhães

Thank you again!

>
>
> [1] http://xmlgraphics.apache.org/batik/using/scripting/java.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Appending a child (animateColor) to an element!

Posted by Helder Magalhães <he...@gmail.com>.
Hi Mathieu,


Note that you provide little information about Batik version being
used (SVN checkout? Which revision number?). Also, you don't state
whether you are following the instructions in "Scripting With Java"
[1] (although you seem to, according to the "public void run(){" which
I imagine it's a runnable implementation. Although it's a bit of
overhead, please always try to state this, and other potentially
useful information (Java version, operating system, etc.).


> Let's see my code :
[...]
>            toColor2.setAttributeNS(null, "id","blink2");
[...]
>            toColor2.setAttributeNS(null, "begin", "0s;blink1.end");
[...]
>            toColor1.setAttributeNS(null, "id","blink1");
[...]
>            toColor1.setAttributeNS(null, "begin", "blink2.end");

Aren't the "blink#" in identifiers and SMIL begin creating a circular
reference? I'd suggest you created a static SVG file (declaratively)
in order to check if this works (if you create a sample file you'll be
able to test not just Squiggle but also Opera, IE+ASV, Firefox nightly
builds, etc.). ;-)


> Can you help me, please, to find the mistake? I dont see what could be
> the problem (nothing is null in the appendChild method I call...) ! I
> often add nodes to documents in my projects, and it's the first time i
> had to face this kind of error.

Twice? ;-)


Hope this helps,
  Helder Magalhães


[1] http://xmlgraphics.apache.org/batik/using/scripting/java.html

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org