title: Activity crashes when onStart (onRestart) goes after onCreate
body: <p>I am developing my first Android app (having an experience of developing in other systems e.g. Visual Basic).</p>
  
  <p>A strange error occurs: when I use onStart method after onCreate in java activity class, the activity immediately crashes on its start. Whereas everything works fine without the onStart (with onCreate only). The same thing is when I put onRestart instead of onStart.</p>
  
  <p>It occurs at me in two different activities, Main and Help, which are not similar. Matters why I need to use onStart (onRestart):</p>
  
  <ul>
  <li><p>in MainActivity I wish to fadein layout each time it appears, on the first load and after return from other activities,</p></li>
  <li><p>HelpActivity inflates additional child views with help pages in the same frame (ScrollView), but on device rotation it throws back to Help TOC, initially set to the frame in onCreate. It's not what user would like, you see.</p></li>
  </ul>
  
  <p>Codes and Logcat are applied.</p>
  
  <p>I use old e-reader Pocketbook iq 701 with Android 2.0.1 (plugged via USB) and third-party emulator YouVawe, and error appears on both.</p>
  
  <p>If anyone had faced to the same problem, please tell is this an Android bug or am I doing something wrong. Maybe I could overwork it, but the conventional way according to docs blablabla, will be preferable and more convenient. </p>
  
  <p>Thanx in advance!</p>
  
  <p>MainActivity:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      public Animation fadeIn;
      public View mainView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.activity_main);
          mainView=(View)findViewById(R.id.linearLayoutMain);
          mainView.setVisibility(View.INVISIBLE);   //to fadein later
  
          //fade-in animation to use on activity (re)start
          fadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
      }
  
      @Override
      protected void onStart() {
          super.onStart();
  
          mainView.setVisibility(View.INVISIBLE);
          mainView.startAnimation(fadeIn);
          mainView.setVisibility(View.VISIBLE);
      }
  </code></pre>
  
  <p>HelpActivity:</p>
  
  <pre><code>public class HelpActivity extends Activity {
  
      public LinearLayout layoutHelpFrame;
      public View viewHelpPage;
      public LayoutInflater inflater;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.activity_help);
  
          //frame to display help content
          layoutHelpFrame = (LinearLayout)findViewById(R.id.frameHelp);
  
          //load initially the Help TOC
          inflater = getLayoutInflater();
          viewHelpPage=inflater.inflate(R.layout.help_0, null);
  //if no onStart or if onRestart used, add view here:
  //      layoutHelpFrame.addView(viewHelpPage);
      }
  
      @Override
      protected void onStart() {
          super.onStart();
          //when restarted on orientation change, help page is restored
          layoutHelpFrame.addView(viewHelpPage);
      }
  
      //on click topic links
      public void showHelpTopic(View topiclnk) {
  
          //clear view
          layoutHelpFrame.removeView(viewHelpPage);   
  
          //get corresponding topic Id by link textview Id
          String lnkname=getResources().getResourceEntryName(topiclnk.getId()); 
          String topicN=lnkname.substring(lnkname.length()-1); //1 last char (digit)
          int layoutID = MainActivity.getResId("help_"+topicN, R.layout.class);
  
          //load the Help topic into frame
          viewHelpPage=inflater.inflate(layoutID, null);
          layoutHelpFrame.addView(viewHelpPage);
          layoutHelpFrame.scrollTo(0, 0);
      }
  </code></pre>
  
  <p>LogCat (since the moment of crash):</p>
  
  <pre><code>03-20 06:19:18.136: D/AndroidRuntime(10243): Shutting down VM
  03-20 06:19:18.136: W/dalvikvm(10243): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
  03-20 06:19:18.136: E/AndroidRuntime(10243): Uncaught handler: thread main exiting due to uncaught exception
  03-20 06:19:18.146: E/AndroidRuntime(10243): java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.a_z_b_u_k_a.ourabc/ru.a_z_b_u_k_a.ourabc.HelpActivity}: java.lang.ClassCastException: android.widget.ScrollView
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2484)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1835)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at android.os.Handler.dispatchMessage(Handler.java:99)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at android.os.Looper.loop(Looper.java:123)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at android.app.ActivityThread.main(ActivityThread.java:4325)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at java.lang.reflect.Method.invokeNative(Native Method)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at java.lang.reflect.Method.invoke(Method.java:521)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at dalvik.system.NativeStart.main(Native Method)
  03-20 06:19:18.146: E/AndroidRuntime(10243): Caused by: java.lang.ClassCastException: android.widget.ScrollView
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at ru.a_z_b_u_k_a.ourabc.HelpActivity.onCreate(HelpActivity.java:25)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2431)
  03-20 06:19:18.146: E/AndroidRuntime(10243):    ... 11 more
  03-20 06:19:18.156: I/dalvikvm(10243): threadid=7: reacting to signal 3
  03-20 06:19:18.156: E/dalvikvm(10243): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
  03-20 06:19:57.116: D/AndroidRuntime(10322): Shutting down VM
  03-20 06:19:57.116: W/dalvikvm(10322): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
  03-20 06:19:57.116: E/AndroidRuntime(10322): Uncaught handler: thread main exiting due to uncaught exception
  03-20 06:19:57.126: E/AndroidRuntime(10322): java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.a_z_b_u_k_a.ourabc/ru.a_z_b_u_k_a.ourabc.MainActivity}: java.lang.NullPointerException
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2484)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1835)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at android.os.Handler.dispatchMessage(Handler.java:99)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at android.os.Looper.loop(Looper.java:123)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at android.app.ActivityThread.main(ActivityThread.java:4325)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at java.lang.reflect.Method.invokeNative(Native Method)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at java.lang.reflect.Method.invoke(Method.java:521)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at dalvik.system.NativeStart.main(Native Method)
  03-20 06:19:57.126: E/AndroidRuntime(10322): Caused by: java.lang.NullPointerException
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at ru.a_z_b_u_k_a.ourabc.MainActivity.onCreate(MainActivity.java:44)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2431)
  03-20 06:19:57.126: E/AndroidRuntime(10322):    ... 11 more
  03-20 06:19:57.136: I/dalvikvm(10322): threadid=7: reacting to signal 3
  03-20 06:19:57.136: E/dalvikvm(10322): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
  </code></pre>