title: How can i declare a variable outside of a method and then initialize them inside of OnCreate()?
body: <p>My question is the same that is here <a href="https://stackoverflow.com/questions/33192284/getextras-on-a-null-object-reference/42237978#42237978">.getExtras()&#39; on a null object reference</a></p>
  
  <p>But i dont know how to do that codeMagic says: "You would need to declare them outside of the method and initialize them inside of onCreate(). That or pass the values you need to the necessary functions"</p>
  
  <p>Sorry i'm very new to the programming world.
      `package ejemplo1.listaejemplo;</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Context;
  import android.view.View;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.ViewGroup;
  
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.TextView;
  
  
  public class Lista extends Activity {
  
      private ListView lista;
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.lista);
  
          String elem1 = getIntent().getExtras().getString("Nombre");
          String elem2 = getIntent().getExtras().getString("Sexo");
  
          Espacios[] datos = new Espacios[] {
                  new Espacios(elem1, elem2),
                  new Espacios("Nombre2", "Sexo2")};
  
          lista = (ListView)findViewById(R.id.Interesar);
  
          Adapta adaptador = new Adapta(this, datos);
          lista.setAdapter(adaptador);
  
      }
      class Adapta extends ArrayAdapter&lt;Espacios&gt; {
  
          String elem1 = getIntent().getExtras().getString("Nombre");
          String elem2 = getIntent().getExtras().getString("Sexo");
  
          Espacios[] datos = new Espacios[] {
                  new Espacios(elem1, elem2),
                  new Espacios("Nombre2", "Sexo2")};
  
          public Adapta(Context context, Espacios[] datos) {
              super(context, android.R.layout.simple_list_item_2, datos);
          }
  
          public View getView(int position, View convertView, ViewGroup parent) {
  
              LayoutInflater inflater = LayoutInflater.from(getContext());
              View item = inflater.inflate(android.R.layout.simple_list_item_2, null);
  
              TextView texto1 = (TextView) item.findViewById(android.R.id.text1);
  
              texto1.setText(datos[position].getNombre());
  
              TextView texto2 = (TextView) item.findViewById(android.R.id.text2);
              texto2.setText(datos[position].getSexo());
  
  
  
              return(item);
  
  
          }
  
      }
  
  
  }
  `
  </code></pre>