title: Setting text in textview in onCreate method
body: <p>It's the third day when I try to solve this problem. I have "Wyniki" activity which is started by "Ekran" activity. In Wyniki's "onCreate" metod I specify setting the label's text which is taken from Ekran's calculations in this way:</p>
  
  <p>My Ekran.java:</p>
  
  <pre><code>package com.example.fizyka;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v7.app.ActionBarActivity;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.EditText;
  
  public class Ekran extends ActionBarActivity {
      public final static String DANE_X = "Fizyka.DANE_WEJSCIE";
      public final static String EPSILON = "Fizyka.EPSILON";
      public final static String EPSILON_POTEGI = "Fizyka.EPSILON_POTEGI";
      public final static String SREDNIA = "Fizyka.SREDNIA";
      public final static String NIEPEWNOSC = "Fizyka.NIEPEWNOSC";
      public final static String EPSILON_POTEGI_SUMA = "Fizyka.EPSILON_POTEGI_SUMA";
  
  public void srednia (View view){
       EditText wejscie = (EditText) findViewById(R.id.wejscie);
       String dane_wejscie = wejscie.getText().toString();
       String arr[] = dane_wejscie.split("\\r?\\n");
       List&lt;Double&gt; dane = new ArrayList&lt;Double&gt;();
       for(int i = 0; i &lt; arr.length;i++){
           dane.add(Double.parseDouble(arr[i].trim().replaceAll(",", ".")));}
  
       //Licze srednia
       Double srednia = 0.0;
       for(int i = 0; i &lt; dane.size();i++){
           srednia = srednia + dane.get(i);}
       srednia = srednia / arr.length;
  
       //Odejmuje średnią od danych
       Double[] roznice = new Double[arr.length];
       for(int i = 0;i &lt; dane.size();i++){
           roznice[i]=dane.get(i)-srednia;
       }
  
       //Kwadraty roznic i ich suma
       Double[] roznice_sq = new Double[arr.length];
       Double suma_roznice_sq =0.0;
       for(int i = 0;i &lt; dane.size();i++){
           roznice_sq[i]=Math.pow(roznice[i],2);
       }
       for(int i = 0;i &lt; dane.size();i++){
           suma_roznice_sq=suma_roznice_sq+roznice_sq[i];
       }
  
       //Niepewność typu A
       double Ua=Math.sqrt((suma_roznice_sq/(arr.length*(arr.length-2))));
       //Przygotowanie do wysyłki
      Intent wysylka = new Intent(this,Wyniki.class);
      wysylka.putExtra(DANE_X, dane_wejscie);
      wysylka.putExtra(EPSILON, Arrays.toString(roznice));
      wysylka.putExtra(EPSILON_POTEGI, Arrays.toString(roznice_sq));
      wysylka.putExtra(SREDNIA, srednia);
      wysylka.putExtra(EPSILON_POTEGI_SUMA, suma_roznice_sq);
        wysylka.putExtra(NIEPEWNOSC, Ua);
        startActivity(wysylka);
  }
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_ekran);
  
          if (savedInstanceState == null) {
              getSupportFragmentManager().beginTransaction()
                      .add(R.id.container, new PlaceholderFragment()).commit();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
  
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.ekran, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      /**
       * A placeholder fragment containing a simple view.
       */
      public static class PlaceholderFragment extends Fragment {
  
          public PlaceholderFragment() {
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              View rootView = inflater.inflate(R.layout.fragment_ekran,
                      container, false);
              return rootView;
          }
      }
  
  }
  </code></pre>
  
  <p>My Wyniki.java:</p>
  
  <pre><code>package com.example.fizyka;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v7.app.ActionBarActivity;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  public class Wyniki extends ActionBarActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_wyniki);
          Intent odbior = getIntent();
          Double Ua_wynik = odbior.getDoubleExtra(Ekran.NIEPEWNOSC,0);
          String Ua_ww = Double.toString(Ua_wynik);
          System.out.println(Ua_ww);
          TextView textView = (TextView) findViewById(R.id.wyniki_finalne);
          textView.setText(Ua_ww);
  
          if (savedInstanceState == null) {
              getSupportFragmentManager().beginTransaction()
                      .add(R.id.container, new PlaceholderFragment()).commit();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
  
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.wyniki, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      /**
       * A placeholder fragment containing a simple view.
       */
      public static class PlaceholderFragment extends Fragment {
  
          public PlaceholderFragment() {
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              View rootView = inflater.inflate(R.layout.fragment_wyniki,
                      container, false);
              return rootView;
          }
      }
  
  }
  </code></pre>
  
  <p>fagment_ekran.xml:</p>
  
  <pre><code>&lt;ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"&gt;
  &lt;LinearLayout android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      &gt;
  
      &lt;EditText
          android:id="@+id/wejscie"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:hint="Dane..."
          android:gravity="top"&gt;
      &lt;/EditText&gt;
      &lt;Button
          android:id="@+id/przycisk"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Oblicz"
          android:onClick="srednia"
          android:gravity="center"&gt;&lt;/Button&gt;
      &lt;TextView
          android:id="@+id/wynik"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"&gt;
  &lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>fragment_wyniki.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TableLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/tableLayout1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:shrinkColumns="*"
      android:stretchColumns="*" &gt;
  
  
      &lt;TableRow
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;TextView
              android:gravity="center"
              android:text="x"
              android:textStyle="bold" &gt;
          &lt;/TextView&gt;
  
          &lt;TextView
              android:id="@+id/TextView23"
              android:gravity="center"
              android:text="ε=x-x̄"
              android:textStyle="bold"&gt;
          &lt;/TextView&gt;
  
          &lt;TextView
              android:id="@+id/TextView24"
              android:gravity="center"
              android:text="ε²"
              android:textStyle="bold"&gt;
          &lt;/TextView&gt;
      &lt;/TableRow&gt;
  
      &lt;TableRow
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;TextView
              android:id="@+id/wartosci_x"
              android:gravity="center"
              android:text="x"
              android:textStyle="bold" &gt;
          &lt;/TextView&gt;
  
          &lt;TextView
              android:id="@+id/wartosci_epsilon"
              android:gravity="center"
              android:text="ε=x-x̄"
              android:textStyle="bold"&gt;
          &lt;/TextView&gt;
  
          &lt;TextView
              android:id="@+id/wartosci_epsilon_pow"
              android:gravity="center"
              android:text="ε²"
              android:textStyle="bold"&gt;
          &lt;/TextView&gt;
      &lt;/TableRow&gt;
      &lt;TableRow 
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
         &lt;TextView
              android:id="@+id/wyniki_finalne"
              android:gravity="center"
              android:text="Wróć"
              android:textStyle="bold"&gt;
          &lt;/TextView&gt;
  
          &lt;TextView/&gt;
          &lt;Button
              android:layout_width="wrap_content"
              android:textSize="6pt"
              android:text="Wróć"
              android:gravity="center"
              /&gt;  
  
      &lt;/TableRow&gt;
      &lt;TableRow
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
         &lt;TextView/&gt;
          &lt;TextView/&gt;
          &lt;Button
              android:layout_width="wrap_content"
              android:textSize="6pt"
              android:text="Eksportuj do TXT..."
              android:gravity="center"
              /&gt;  
  
      &lt;/TableRow&gt;
  
  
  &lt;/TableLayout&gt;
  </code></pre>
  
  <p>This brings me bunch of errors:</p>
  
  <pre><code>04-17 10:18:49.766: E/AndroidRuntime(743): FATAL EXCEPTION: main
  04-17 10:18:49.766: E/AndroidRuntime(743): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fizyka/com.example.fizyka.Wyniki}: java.lang.NullPointerException
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.os.Handler.dispatchMessage(Handler.java:99)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.os.Looper.loop(Looper.java:137)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.app.ActivityThread.main(ActivityThread.java:4745)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at java.lang.reflect.Method.invokeNative(Native Method)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at java.lang.reflect.Method.invoke(Method.java:511)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at dalvik.system.NativeStart.main(Native Method)
  04-17 10:18:49.766: E/AndroidRuntime(743): Caused by: java.lang.NullPointerException
  04-17 10:18:49.766: E/AndroidRuntime(743):  at com.example.fizyka.Wyniki.onCreate(Wyniki.java:25)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.app.Activity.performCreate(Activity.java:5008)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  04-17 10:18:49.766: E/AndroidRuntime(743):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
  04-17 10:18:49.766: E/AndroidRuntime(743):  ... 11 more
  </code></pre>
  
  <p>Wyniki.java:25 is <code>textView.setText(Ua_ww);</code> line. Can I blame TableLayout?</p>
  
  <p>UPDATE Wyniki.java:</p>
  
  <pre><code>package com.example.fizyka;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v7.app.ActionBarActivity;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  public class Wyniki extends ActionBarActivity {
      private static String Ua_ww;
       @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Intent odbior = getIntent();
          Double Ua_wynik = odbior.getDoubleExtra(Ekran.NIEPEWNOSC,0);
          Ua_ww = Double.toString(Ua_wynik);
          System.out.println(Ua_ww);
  
          if (savedInstanceState == null) {
              getSupportFragmentManager().beginTransaction()
                      .add(R.id.container, new PlaceholderFragment()).commit();
          }
      }
  
      public static class PlaceholderFragment extends Fragment {
  
          public PlaceholderFragment() {
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              View rootView = inflater.inflate(R.layout.fragment_wyniki,null);
               TextView textView = (TextView) rootView.findViewById(R.id.wyniki_finalne);
           textView.setText(Ua_ww);
  
              return rootView;
          }
      }
  
  }
  </code></pre>