| 

.NET C# Java Javascript Exception

Problem: null elements in a Vector

Dies ist das Archiv des ehemaligen Forums zum Thema Groovy, Grails, Griffon und Bean Scripting Framework, welches unter groovy-forum.de existierte. Die neue Adresse des Groovy-Forums ist: http://codekicker.de/fragen/themen/groovy.


Problem: null elements in a Vector

hernia - 23.08.2010 18:18
Hi! I'm writing a script in Groovy -my first time-. The synthesized code where I'm getting the error is that:

//////////THIS ABSTRACT CLASS IS WRITTEN IN JAVA/////////////
public abstract class BaseFormation {
    public Vector<Player> form;
    /*.....*/

    public void set_team_name() {
    /*.....*/
    }
}

/////////THIS CLASS IS WRITTEN IN GROOVY, EXTENDING THE JAVA CLASS ABOVE////////
public class Formation extends BaseFormation {

    public Formation() {
        this.form = new Vector<Player>(10);
        this.set_team_name();
        this.set_formation();
        }

    public void set_formation() {
        Player aux=new Player();

        this.form.add(aux.set_player(2, position.CF, 0.5, 0.5));
        this.form.add(aux.set_player(3, position.SW, 0.5, 0.5));
        this.form.add(aux.set_player(4, position.SB, 0.5, 0.5));
        /* I repeat this 7 more times */

        for (k in 0..9)
            {
                switch(this.form.get(k).pos)
                    {
                    /*.....*/


Where Player is a class (also written in java) containing some variables (pos, home_x, home_y...) and methods (the most important: set_player(), that sets the values from its args into the member variables).

set_player() is working OK, beacause I'm sure that the aux object contains all the values correctly. But the problem is with the add() method. aux object isn't copied ok, and when the "switch" line is executed, I get the next error: exception from Groovy: java.lang.NullPointerException: Cannot get property: pos on null object.

I've tried also with other methods like add(index, object) and also set(index, object) but it's always the same. add() is returning true, so I'm really disoriented.

I'll be very grateful for any help or advice!! I'm very hurry, I have to finish it early! My objective isn't to get an strictly correct Groovy code, I only need that it works! :)

Hernán.


Stelle deine Groovy-Frage jetzt!


Diese Seite zeigt den Thread "Problem: null elements in a Vector" der ehemaligen Webseite groovy-forum.de, welche durch einen Serverunfall zerstört wurde. codekicker.de hat viele Konversationen über die beliebte Programmiersprache Groovy und zugehörige Frameworks wie das Grails-Framework retten können.

Hast Du eine Frage zum Thema Groovy, Grails oder allgemein Java? Viele ehemalige groovy-forum.de Mitglieder beantworten dir auf codekicker.de deine Frage! Stelle jetzt eine Frage!

Viele weitere Diskussionen zu Grails und Groovy befinden sich auf der Threadübersicht des alten groovy-forum.de.