extract value from spinner and use it to calculations -- NullPointerException
<p>I want to use the "value" from the spinner.</p>

<p>When the user makes the choice i want to use that value in order to do some calculations.</p>

<p>My problem is :</p>

<p>1) How to get properly the value (item).I am using sth like  "item.MyOnItemSelectedListener ==0".</p>

<p>2) What the value should be?For example ,above i have ==0 .This means the first choice from the spinner list?</p>

<p>The code:</p>

<pre><code>public class number_cores extends Activity implements OnClickListener {
    ..
    final Spinner spinner = (Spinner) findViewById(R.id.spinner);

        ...
  public void onCreate(Bundle savedInstanceState) {
 ....


 //spinner-drop_list
        ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(
                this, R.array.init_or_final, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
    }
...
public void cores_func(){
           ...
             double fcores=0;

             MyOnItemSelectedListener obj=new MyOnItemSelectedListener();

         if ( obj.getPosition()==0) fcores=initcores*Math.exp(-l*ttime);
         else if (obj.getPosition()==1) fcores=initcores/Math.exp(-l*ttime);

..}

 //spinner class

        public class MyOnItemSelectedListener implements OnItemSelectedListener {

            private int position;
        public int getPosition() {return position;}

            public void onItemSelected(AdapterView&lt;?&gt; parent,
                View view, int pos, long id) {
                 position=pos;

            }

            public void onNothingSelected(AdapterView &lt;?&gt; parent) {
              // Do nothing.
            }
        }
</code></pre>

<p>Thanks!</p>
