<br><br><div><span class="gmail_quote">On 6/10/07, <b class="gmail_sendername">eduard aylon</b> &lt;<a href="mailto:eduard.aylon@gmail.com">eduard.aylon@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi list,<br><br>I am trying to make a list of objects where each object has<br>references to other objects, but I am not succeeding and I get a<br>NullPointerException. The piece of code below may represent what I am<br>trying to do.
</blockquote><div><br><br>One more reply to this, it might be obvious by now but I needed a workaround myself and was happy to find one, if a ugly one. Here&#39;s a edited version of the original demonstration code that gets around the bug. clearly this isn&#39;t going to work if the length of the array isn&#39;t defined in the code but is instead determined by the outcome of some opperation. Right now I don&#39;t think it&#39;s possible to have ChucK generate names for class instances as ChucK can&#39;t generate ChucK code, then run it. Somebody kindly corect me if I overlooked something in that regard. This would get quite anoying if -say- 50 &quot;Items&quot; were needed but if a dozen or so would do this might get people by untill this is fixed in a future version.
<br><br>Yours,<br>kas.<br><br>==========================<br>class object<br>{<br>&nbsp;&nbsp;&nbsp; Std.rand2f(0., 1.) =&gt; float f_;<br>}<br><br>class Item extends object<br>{<br>&nbsp;&nbsp;&nbsp; 2 =&gt; int size_;<br>&nbsp;&nbsp;&nbsp; object item_[size_];<br><br>
&nbsp;&nbsp;&nbsp; fun void print()<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for( 0=&gt;int i; i&lt;size_; i++ )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt;&lt; &quot;item [&quot;,i,&quot;]&quot;, item_[i].f_&gt;&gt;&gt;;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &lt;&lt;&lt;&quot;----------------------------------------------&quot;&gt;&gt;&gt;;
<br>&nbsp;&nbsp;&nbsp; &lt;&lt;&lt;&quot;calling print from within class definition&quot;&gt;&gt;&gt;;<br>&nbsp;&nbsp;&nbsp; &lt;&lt;&lt;&quot;----------------------------------------------&quot;&gt;&gt;&gt;;<br>&nbsp;&nbsp;&nbsp; print();<br>}<br><br>//4 =&gt; int n; (edited out by Kassen)
<br><br>// ugly and less versatile workaround starts here<br>//this forces initiation to happen outside of the array<br><br>Item a;<br>Item b;<br>Item c;<br>Item d;<br><br>//now we asign these to the array<br>[a,b,c,d] @=&gt; Item l[];
<br><br>//end of workaround<br><br>// no problems up until here<br><br>&lt;&lt;&lt;&quot;----------------------------------------------&quot;&gt;&gt;&gt;;<br>&lt;&lt;&lt;&quot;calling print from outside class definition&quot;&gt;&gt;&gt;;
<br>&lt;&lt;&lt;&quot;----------------------------------------------&quot;&gt;&gt;&gt;;<br><br>//notice I had to replace &quot;n&quot; by &quot;l.cap()&quot; here <br>//this is functionally equivalent anyway<br>for( 0=&gt;int i; i&lt;
l.cap(); i++ )<br>&nbsp;&nbsp;&nbsp; l[i].print();&nbsp;&nbsp; //offending line<br></div><br></div><br>==================================================