There was some time since I used Chuck now, so I may be wrong on this one. But I get the feeling that you're not initializing l, right?
That's what I thought at first with the original code but with the code below every object contained in l is automatically initialised when the list is declared. That's why after Item l[n], print() is called all items and each object's float is printed to stdout.
On 10/06/07, eduard aylon
wrote: Hi list,
I am trying to make a list of objects where each object has references to other objects, but I am not succeeding and I get a NullPointerException. The piece of code below may represent what I am trying to do.
class object { Std.rand2f(0., 1.) => float f_; }
class Item extends object { 2 => int size_; object item_[size_];
fun void print() { for( 0=>int i; i
>>; } <<<"----------------------------------------------">>>; <<<"calling print from within class definition">>>; <<<"----------------------------------------------">>>; print(); } 4 => int n; Item l[n];
// no problems up until here
<<<"----------------------------------------------">>>; <<<"calling print from outside class definition">>>; <<<"----------------------------------------------">>>;
for( 0=>int i; i
After execution I get: [chuck](VM): NullPointerException: shred[id=1:test.ck], PC=[37]
Excuse me if it's too obvious, but I can't see why it rises the null pointer exception. Any ideas?
thanks in advance,
eduard
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Love. /Bruce Harris
-- -----BEGIN 2ROT13 MESSAGE----- Low Bitrate Netlabel: http://f-label.tojt.net/ Blog: http://gameboygenius.8bitcollective.com/ Sätt på ett par flipflops, vippa på rumpan och gör det här till en minnesvärd sommar! -----END 2ROT13 MESSAGE----- _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users