Strange 2 NullPointerException on onCreate of android activity
<p>Please help, I have dig into the onSaveInstanceState things and onConfigChange things, but can't get the picture.</p>

<p>The exception was reported for my published app via Google Play, but I can not reproduce it in my development environment. After tracking, I found there are 2 NullPointerException happened in the onCreate method of PreviewActivity:</p>

<p><strong>Issue 1:</strong></p>

<p>(a). Code in PreviewActivity's onCreate method:</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
   setContentView(R.layout.logo_preview_layout);
   ...

   mBtnCheckGuess = (Button)findViewById(R.id.btn_check_guess);  
   mVgGuessPanel = (View)findViewById(R.id.layout_guess); // the exception line!

   ...

}
</code></pre>

<p>(b). Code in layout xml (only part of it)</p>

<pre><code>&lt;ScrollView 
    android:gravity="center_horizontal" 
    android:orientation="vertical" 
    android:id="@+id/main_layout" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:layout_marginTop="25.0dip" android:layout_marginBottom="10.0dip"&gt;
    &lt;LinearLayout 
        android:orientation="vertical" 
        android:layout_width="fill_parent" android:layout_height="wrap_content"&gt;            
        &lt;RelativeLayout
            android:id="@+id/layout_guess"
            android:layout_gravity="center_horizontal" 
            android:layout_width="fill_parent" android:layout_height="wrap_content" 
            android:layout_marginTop="0.0dip" android:layout_marginBottom="0.0dip" 
            android:visibility="visible"&gt;
</code></pre>

<p>I am totally sure that's no other @id/layout_guess in this layout xml file.</p>

<p>(c). Code in AndroidManifest.xml</p>

<pre><code>    &lt;activity
        android:name=".PreviewActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:screenOrientation="portrait"&gt;
    &lt;/activity&gt;
</code></pre>

<p>I have got dozens NullPointerException for this issue, but after I removed this line in AndroidManifest:</p>

<pre><code>android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
</code></pre>

<p>I have not got the same issue for the new release version app for these 2 days. I totally don't know why...</p>

<p><strong>Issue 2:</strong>
Background, I want to pass a object from Activity A to Activity B when A starts B, I used Android's Application object to contain this object in its instance variable.</p>

<p>(a)Code for MyApplication:</p>

<pre><code>public class MyApplication extends Application{
Logo mSelectedLogo;

@Override
public void onCreate(){
}

public void setSelectedLogo(Logo logo){
    mSelectedLogo = logo;
}
public Logo getSelectedLogo(){
    return this.mSelectedLogo;
}
}
</code></pre>

<p>(b) part code of Activity A</p>

<pre><code>mApplication.setSelectedLogo(logo);
            Intent intent = new Intent(this, ActivityB.class);
            LogoListActivity.this.startActivityForResult(intent, REQUEST_GUESS);
</code></pre>

<p>(c) code of Activity B</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
    ...
    MyApplication mApplication = (MyApplication)this.getApplication();
    mSelectedLogo = mApplication.getSelectedLogo();
    ALog.d(TAG, "correct logo name: " + mSelectedLogo.mName + ", id: " + mSelectedLogo.mId); // NullPointerException line, obviously mApplication.getSelectedLogo() returns NULL
    ...
}
</code></pre>

<p>It's really strange why it will be NULL. Unless the MyApplication object has been destroyed.</p>

<p>Error log's here:</p>

<p><code>
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.codefes.quiz/com.codefes.quiz.PreviewActivity}:     java.lang.NullPointerException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.NullPointerException
    at com.codefes.quiz.PreviewActivity.onCreate(Unknown Source)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
    ... 11 more
</code></p>

<p>Please help, thank you!</p>
