title: Null object reference if configuration changes
body: <p>I get null object reference if configuration changes for only <code>LinearLayout</code> objects.</p>
  
  <p><strong>landscape</strong> mode I have to <code>setVisiblity = View.GONE</code> for all views except one view </p>
  
  <p><strong>portrait</strong> mode I have to <code>setVisibility = View.VISIBLE</code> for all views: </p>
  
  <pre><code>if (Activity started in portrait mode then turned into landscape) 
  {it work fine}
  else {it get null object reference only for linearLayout objects}
  </code></pre>
  
  <p>objects return this error are called <code>chart</code> , <code>progress_layout</code> .</p>
  
  <p><strong>edited</strong></p>
  
  <p><strong>most of class "related code snippet" cause full class 1000 line cannot post it</strong></p>
  
  <pre><code>public class Cardio extends ActionBarActivity implements InsertDialogue.Insert, saveDialogue.Save, HistoryDialogue.History, AdapterView.OnItemSelectedListener {
      float Float;
      int Day = 0;
      Database database;
      int i;
      int num;
      static Spinner spinner;
      static int pos;
      Progress p;
      SubActionButton goalSubButton;
      boolean gool = false;
      YAxis leftAxis ;
      LineChart Running_LineChart ;
      int intent ;
      FloatingActionMenu x ;
      FloatingActionButton actionButton ;
      String orientation ;
      LinearLayout historyText ;
      ArrayList&lt;Entry&gt; Running_ArrayEntry ;
      int First_entries ;
      LinearLayout chart  ;
      LinearLayout progress_layout ;
      boolean HistoryTextAfterRotation ;
  
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          historyText = (LinearLayout) findViewById(R.id.historyLayoutText);
          chart = (LinearLayout) findViewById(R.id.chartid);
          progress_layout = (LinearLayout) findViewById(R.id.group);
          Running_LineChart = (LineChart) findViewById(R.id.chart);
          Log.e("oncreate","oncreate");
          getWindow().getDecorView().setSystemUiVisibility(
                  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                          | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
          database = new Database(this);
          Bundle extras = getIntent().getExtras();
          intent = extras.getInt("activity");
          p = new Progress();
          orientation = getRotation();
          if( savedInstanceState == null) {
              getSupportFragmentManager().beginTransaction()
                      .add(R.id.group, p)
                      .commit();
          }
          else
          {
              String ftagment =  savedInstanceState.getString("frag");
              getSupportFragmentManager().beginTransaction()
                      .add(p,ftagment)
                      .commit();
          }
          addPlus();
          switch (orientation) {
              case "l":
                  actionButton.setVisibility(View.GONE);
                  break;
              case "p" :
                  actionButton.setVisibility(View.VISIBLE);
                  break;
          }
      }
  
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
          orientation = getRotation() ;
          setGoalSubButton_Visiblity();
          if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
              if(actionButton!=null&amp;&amp;actionButton.getVisibility()!=View.GONE) {
                  actionButton.setVisibility(View.GONE);
              }
              if(spinner!=null&amp;&amp;spinner.getVisibility()!=View.GONE) {
                  spinner.setVisibility(View.GONE);
              }
          //   p.setUserVisibleHint(false);
  
  
              if(progress_layout!=null&amp;&amp;progress_layout.getVisibility()!=View.GONE) {
                  progress_layout.setVisibility(View.GONE);
              }
  
              if(chart!=null&amp;&amp;chart.getVisibility()!=View.GONE) {
                  chart.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
              }
              if(historyText!=null&amp;&amp;historyText.getVisibility()!=View.GONE) {
                  historyText.setVisibility(View.GONE);
              }
              if(Running_LineChart!=null&amp;&amp;Running_LineChart.getVisibility()!=View.GONE) {
                  Running_LineChart.animateY(1300);
              }
              // Changes the height and width to the specified *pixels*
              //   chart = (LinearLayout) findViewById(R.id.chartid);
              //  chart.getLayoutParams().height = LayoutParams.MATCH_PARENT;
              //   setContentView(R.layout.activity_main_land);
              //  Toast.makeText(this,"chnge orientation",Toast.LENGTH_SHORT).show();
          }
          else if(newConfig.orientation ==Configuration.ORIENTATION_PORTRAIT) {
              actionButton.setVisibility(View.VISIBLE);
              spinner.setVisibility(View.VISIBLE);
              p.setUserVisibleHint(false);
              Log.e("BEFORE LOG","BEFOR PROGRESS LAYOUT ");
              progress_layout.setVisibility(View.VISIBLE);
              chart.getLayoutParams().height =0;
              if(HistoryTextAfterRotation&amp;&amp;historyText.getVisibility()!=View.VISIBLE) {
                  historyText.setVisibility(View.VISIBLE);}
              Running_LineChart.animateY(1300);
              x.close(true);
          }
          super.onConfigurationChanged(newConfig);
  
  
      }
        public String getRotation(){
          final int rotation = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getOrientation();
          switch (rotation) {
              case Surface.ROTATION_0:
                  return "p";
              case Surface.ROTATION_90:
                  return "l";
              case Surface.ROTATION_180:
                  return "p";
              default:
                  return "l";
          }
  
      }
  
  
  
      public void setGoalSubButton_Visiblity() {
          orientation = getRotation() ;
          switch (orientation) {
           case "p": {
               if (getIdsFromGoalLimitsTables()) {
                   x.close(true);
                   actionButton.removeAllViews();
                   actionButton.detach();
                   Log.e("mohab", "gool must be visible ");
                   addPlus();
                   p.setGoal_unset();
               } else {
                   x.close(true);
                   actionButton.removeAllViews();
                   actionButton.detach();
                   Log.e("mohab", "gool must be invisible");
                   addPlus();
                   p.setGoal(getgoalFromDatabase());
               }
            }
         }
          updateProgress();
          addEntries(0, 0, true,false,0);
  
      }
  
  
  
      @Override
      protected void onSaveInstanceState(Bundle savedInstanceState) {
          if (p != null) {
              savedInstanceState.putString("frag",
                      p.getTag());
          }
          super.onSaveInstanceState(savedInstanceState);
      }
  
  
  
      @Override
      protected void onResume() {
          super.onResume();
          setSpinner();
          setGoalSubButton_Visiblity();
         // addEntries(0, 0, true, false, 0);  // cause its added in setGoal event
      }
  </code></pre>
  
  <p><strong>manifest</strong></p>
  
  <pre><code> &lt;activity
          android:name=".Cardio.Cardio"
          android:configChanges="orientation|screenSize"
          &gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p><strong>Logcat</strong></p>
  
  <pre><code>    10-10 07:05:42.721: E/AndroidRuntime(4115): FATAL EXCEPTION: main
  10-10 07:05:42.721: E/AndroidRuntime(4115): Process: developer.mohab.gymee, PID: 4115
  10-10 07:05:42.721: E/AndroidRuntime(4115): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.setVisibility(int)' on a null object reference
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at developer.mohab.gymee.Cardio.Cardio.onConfigurationChanged(Cardio.java:154)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:4150)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:4225)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1461)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at android.os.Handler.dispatchMessage(Handler.java:102)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at android.os.Looper.loop(Looper.java:211)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at android.app.ActivityThread.main(ActivityThread.java:5389)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at java.lang.reflect.Method.invoke(Native Method)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at java.lang.reflect.Method.invoke(Method.java:372)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
  10-10 07:05:42.721: E/AndroidRuntime(4115):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
  </code></pre>
  
  <p><strong>xml file</strong></p>
  
  <pre><code>    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:weightSum="5"
      android:orientation="vertical"
      tools:context=".MainActivity"
      android:id="@+id/layout"
      android:background="@android:color/white"&gt;
  
  
  
  
     &lt;LinearLayout
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:layout_weight="3"
         android:orientation="vertical"
         android:id="@+id/chartid"
         android:background="@color/gridBack"&gt;
      &lt;com.github.mikephil.charting.charts.LineChart
          android:id="@+id/chart"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_marginTop="25dp"
           /&gt;
     &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:gravity="center"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:id="@+id/historyLayoutText"&gt;
          &lt;TextView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:gravity="center"
              android:textColor="@color/start"
              android:textSize="23dp"
              android:layout_marginTop="5dp"
              android:text="History" /&gt;
      &lt;/LinearLayout&gt;
  
  
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:id="@+id/linearLayout2"
          android:layout_weight="2"
          android:gravity="right"
          android:orientation="horizontal"
  
          &gt;
          &lt;LinearLayout
              android:id="@+id/group"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:layout_weight="1"
              &gt;
          &lt;/LinearLayout&gt;
  
          &lt;Spinner
              android:layout_width="130dp"
              android:layout_height="50dp"
              android:layout_marginTop="10dp"
              android:id="@+id/spinner"
  
            /&gt;
  
  
      &lt;/LinearLayout&gt;
  
  
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>thanx in advance!</p>