Instantiate variables in class instead of onCreate() wrong?
<p>Is something wrong with this construct in Android?</p>

<pre><code>class A extends Activity {

private Object myObject = new Object();

@Override
protected void onCreate(Bundle savedInstanceState) {
    //myObject = new Object();
}
</code></pre>

<p>}</p>

<p>Because at some point(s) later I get (sometimes, not reproducible yet) exceptions because myObject is null. I don't know if it's because I have to initialize in onCreate.</p>

<p><strong>Edit</strong>: Additional details: </p>

<ul>
<li><p>The actual class of myObject is <code>List&lt;Object&gt;</code> (Where Object is a domain specific type)</p></li>
<li><p>At some point later in the activity <strong>I'm storing myObject as a static field of a "Parameter passer" class and starting other Activity</strong> (because I'm avoiding to implement Parcelable. If this is good or bad practice should not be discussed here, unless that's causing my error). In the other Activity I pick up myObject. There it's (sometimes) null.</p></li>
</ul>

<p><strong>Edit 2</strong>: I don't understand why this object becomes null if I'm storing a reference to it as static field of my parameter passer class (a standalone, dedicated class). That's how garbage collection works, right, it just removes when the objects are not referenced anymore. So since I have a static reference this object should not be removed. According to this thoughts, if they are correct, the problem should be somewhere else.</p>
