This site requires JavaScript, please enable it in your browser!
Greenfoot back
swap587
swap587 wrote ...

2013/9/8

Null value Exception

swap587 swap587

2013/9/8

#
Inspector ins = (Inspector)(getOneObjectAtOffset(0, 0 , Inspector.class)); ins.action(); - I am just trying to call a method of the class Inspector but unable to do it. Any suggestions. It does not give an error on compiling but gives error on run time.
JetLennit JetLennit

2013/9/8

#
Try
Inspector ins = getOneObjectAtOffset(0, 0 , Inspector.class);
swap587 swap587

2013/9/8

#
It gives incompatible type error message...
JetLennit JetLennit

2013/9/8

#
Could you give the entire class?
erdelf erdelf

2013/9/8

#
try
    
if(getOneObjectAtOffset(0,0,Inspector.class)!=null)
{
Inspector ins = (Inspector)getOneObjectAtOffset(0, 0 , Inspector.class);
ins.action();
}
Gevater_Tod4711 Gevater_Tod4711

2013/9/8

#
@erdelf You should try not to call the same method two times if it's not neccessary. If you just check whether 'ins' is null you call the getOneObjectAtOffset method only one time which makes your code perform faster. Your code would also work and concerning the method getOneObjectAtOffset it wouldn't realy matter because the method has a very low runtime. But when you use methods with e.g. an exponential runtime it will mater.
You need to login to post a reply.