NPE on saving instance : Cannot invoke method leftShift() on null object

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

NPE on saving instance : Cannot invoke method leftShift() on null object

Julienoune
Hello all I have some domain classes like that
class University {
     static hasMany = [ students: Student ]
}

class Student {
     static belongsTo = [university:University ]
     
     Person person
}

class Person extends BasicPerson{
     
}

class BasicPerson {
    Address address
}

class Address {
    static belongsTo = [basicPerson:BasicPerson]
}
So, I'm trying to update an existing Student. My code in the controller is the following :
	def update = {
		Student student = Student.get(params.id)
				Student.withTransaction { status ->
					bindData(student,params)
					
					Person person
					Adress adress
					person = cand.person
					adress = cand.person.adress
					

					bindData(person, params)
						
					if (adress != null)
						bindData(adress,params)
					else {
						adress = new Adress(params)
						personne.adress = adress
					}
				
					student.person = person
					
					if (person.hasErrors() || !person.save(flush:true)) {
						person.errors.allErrors.each {
							errors << [id: it.field, endroit: 'person', msg: g.message(error: it)]
						}
					}
		
					if (student.hasErrors() || !student.save(flush:true)) {
						student.errors.allErrors.each {
							errors << [id: it.field, endroit: 'student', msg: g.message(error: it)]
						}
					}
				}
	}
My error happens on the student saving, but I cannot figure out why? java.lang.NullPointerException: Cannot invoke method leftShift() on null object Any idea?
Reply | Threaded
Open this post in threaded view
|

Re: NPE on saving instance : Cannot invoke method leftShift() on null object

Julienoune
Forget my post,
I think I need to sleep a lot...

I forgot to initialize errors var

Bye every one.

Julien
Reply | Threaded
Open this post in threaded view
|

Re: NPE on saving instance : Cannot invoke method leftShift() on null object

burtbeckwith
In reply to this post by Julienoune
The only leftShift (<<) calls are the two adding to the 'errors' which isn't declared here. That's probably not being initialized.

Burt

>
> Hello all
>
> I have some domain classes like that
>
> class University {
>      static hasMany = [ students: Student ]
> }
>
> class Student {
>      static belongsTo = [university:University ]
>      
>      Person person
> }
>
> class Person extends BasicPerson{
>      
> }
>
> class BasicPerson {
>     Address address
> }
>
> class Address {
>     static belongsTo = [basicPerson:BasicPerson]
> }
>
>
> So, I'm trying to update an existing Student. My code in the controller is
> the following :
>
> def update = {
> Student student = Student.get(params.id)
> Student.withTransaction { status ->
> bindData(student,params)
>
> Person person
> Adress adress
> person = cand.person
> adress = cand.person.adress
>
>
> bindData(person, params)
>
> if (adress != null)
> bindData(adress,params)
> else {
> adress = new Adress(params)
> personne.adress = adress
> }
>
> student.person = person
>
> if (person.hasErrors() || !person.save(flush:true)) {
> person.errors.allErrors.each {
> errors << [id: it.field, endroit: 'person', msg: g.message(error:
> it)]
> }
> }
>
> if (student.hasErrors() || !student.save(flush:true)) {
> student.errors.allErrors.each {
> errors << [id: it.field, endroit: 'student', msg: g.message(error:
> it)]
> }
> }
> }
> }
>
>
> My error happens on the student saving, but I cannot figure out why?
>
> java.lang.NullPointerException: Cannot invoke method leftShift() on null
> object
>
> Any idea?
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email