title: Unable to start activity ComponentInfo{com.example.list/com.example.list.editbox}: java.lang.NullPointerException
body: <p>i am trying to save the data in list view using Shared Preferences but im getting some errors.
  i have 2 classes one is main activity and 2nd is editbox.</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity 
  {
      ListView listView1=null;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
  
          final ListView listView1 = (ListView) findViewById(R.id.listView1);
  
           String[] items = { "List 1", "List 2", "List 3", "List 4" };
  
  
  
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, items);
  
          listView1.setAdapter(adapter);
  
  
  
          listView1.setOnItemClickListener(new OnItemClickListener() 
          {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id)
              {
  
                  //String item = ((TextView)view).getText().toString();
  
                  //Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show();
  
                  //int pos = (int) listView1.getItemIdAtPosition(position);
  
                  String value = listView1.getAdapter().getItem(position).toString();
  
  
                  Intent it1 = new Intent(getApplicationContext(), editbox.class); 
                  it1.putExtra("index", value );
                  startActivity(it1);
  
              }
          });
  
  
  
      }
  
      public boolean onCreateOptionsMenu(Menu menu) 
      {
  
          super.onCreateOptionsMenu(menu);
          menu.add("List").setIntent(new Intent(this,MainActivity.class));
          return true;
      }
  
  }
  </code></pre>
  
  <p><strong>editbox.java</strong></p>
  
  <pre><code>public class editbox extends Activity 
  {   
      private TextView tv;
      private EditText nameText,nameText1;
      @Override
      protected void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.editbox);
  
          //tv = (TextView) findViewById(R.id.textView1);
  
          //Bundle b = getIntent().getExtras();
          //int poss = b.getInt( "index");
        //  tv.setText("Position = " + poss);
  
  
  
          //Bundle extras=getIntent().getExtras();
          //Intent it = getIntent();
          //int myvalue = it.getIntExtra("id",0);
          //Bundle extras = it.getExtras();
          //String myvalue = extras.getString("data");
  
          //nameText=(EditText)findViewById(R.id.editText1);
          //nameText.setText(poss);
  
           Bundle b = getIntent().getExtras();
           String val = b.getString("index");
          //String val = b.getStringExtra("index");
          SharedPreferences setting = getSharedPreferences("List 1", 0);
  
          nameText.setText(setting.getString("List 1", "poss"));
  
          //nameText.setText(poss);
  
          //display=(EditText)findViewById(R.id.editText1);
          //display.setText(""+ myvalue);
  
  
      }
  
      protected void onStop() 
      {
  
          super.onStop();
  
          SharedPreferences setting = getSharedPreferences("List 1",0);
          SharedPreferences.Editor editor = setting.edit();
          editor.putString("List 1", nameText.getText().toString());
  
          editor.commit();
  
      }
  
  
  
  
      public boolean onCreateOptionsMenu(Menu menu) 
      {
          // Inflate the menu; this adds items to the action bar if it is present.
          //getMenuInflater().inflate(R.menu.main, menu);
          super.onCreateOptionsMenu(menu);
          menu.add("List 1").setIntent(new Intent(this,MainActivity.class));
  
          return true;
      }
  }
  </code></pre>
  
  <p><strong>These are the errors</strong> </p>
  
  <pre><code>03-20 01:03:29.786: E/AndroidRuntime(1272): FATAL EXCEPTION: main
  03-20 01:03:29.786: E/AndroidRuntime(1272): Process: com.example.list, PID: 1272
  03-20 01:03:29.786: E/AndroidRuntime(1272): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.list/com.example.list.editbox}: java.lang.NullPointerException
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.os.Handler.dispatchMessage(Handler.java:102)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.os.Looper.loop(Looper.java:136)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.app.ActivityThread.main(ActivityThread.java:5017)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at java.lang.reflect.Method.invokeNative(Native Method)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at java.lang.reflect.Method.invoke(Method.java:515)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at dalvik.system.NativeStart.main(Native Method)
  03-20 01:03:29.786: E/AndroidRuntime(1272): Caused by: java.lang.NullPointerException
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at com.example.list.editbox.onCreate(editbox.java:53)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.app.Activity.performCreate(Activity.java:5231)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
  03-20 01:03:29.786: E/AndroidRuntime(1272):     ... 11 more
  </code></pre>