title: Why can't I set values to spinner in android
body: <p>I have a Class which when it executes, displays this error: </p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.onth/com.example.onth.Savedlocation}: java.lang.NullPointerException  
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>package com.example.onth;
  
  import java.util.List;
  import org.w3c.dom.Comment;
  import android.media.AudioManager;
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  import android.util.Log;
  import android.view.Menu;
  import android.widget.ArrayAdapter;
  import android.widget.EditText;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class Savedlocation extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          DatabaseHandler db = new DatabaseHandler(this);
  
             Log.d("Reading: ", "Reading all contacts..");
              List&lt;locationprofl&gt; loc = db.getAlllocation();  
              String log = " ";
  
              for (locationprofl cn : loc) {
                   log ="lat: "+cn.getlat()+" long:"+cn.getlong()+" ,Name: " + cn.getName() + " ,Profile: " + cn.getProfile();
                   Log.v("aaa", log);
  
              }
              final Spinner dropdown = (Spinner)findViewById(R.id.spinner1);
              String[] items = new String[]{"General", "Silent", "Outdoor"};
              ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, items);
              dropdown.setAdapter(adapter);
              //addListenerOnButton();    
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.savedlocation, menu);
          return true;
      }
  
  }
  </code></pre>