title: Error in getting text from edittext-Android 2
body: <p>I'm doing a currency converter and i want to only introduce one value and that value is transform in the coins that the user want. When i run the program and click on the bottom to convert it closes the application and in the logcat appears the error- java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference.</p>
  
  <p>I dont know where the error is and i'm a begginer in android.</p>
  
  <pre><code>public class MainActivity extends Activity implements View.OnClickListener{
  
  
  int money1, money2,money3,money4;
  int[] money = {money1,money2,money3,money4};
  int from;
  TextView rate;
  Button button1;
  EditText ed1; 
  EditText ed2; 
  EditText ed3;
  EditText ed4;
  Spinner spinner1;
  Spinner spinner2;
  Spinner spinner3;
  Spinner spinner4;
  
  
  EditText[] values = {ed1,ed2,ed3,ed4};
  
  
   String[] spinnerValues = { "ANGOLAN KWANZA" , "ARGENTINE PESO" , "ARMENIAN DRAM" , "ARUBAN                          FLORIN" , "AUSTRALIAN DOLLAR" , "BELARUSIAN RUBLE" , "BOLIVIAN BOLIVIANO" , "BRAZILIAN REAL" , "CAMBODIAN RIEL","CANADIAN DOLLAR","CHINESE YUAN RENMINBI","EURO","INDIAN RUPEE","JAPANESE YEN", "LIBIAN DINAR","SWISS FRANC","THAI BAHT","BRITISH POUND","US DOLLAR","VIETNAMESE DONG"};
  String[] simbol = { "AOA", "ARS", "AMD","AWG","AUD","BYR","BOB","BRL","KHR","CAD","CNY","EUR",
            "INR","JPY","CHF","THB","GBP","USD","VND","LYD"};
  
   int arr_images[] = { R.drawable.angola, R.drawable.argentina,
          R.drawable.armenia, R.drawable.aruba, R.drawable.australia,
          R.drawable.bielorussia, R.drawable.bolivia, R.drawable.brasil,
          R.drawable.cambodia, R.drawable.canada, R.drawable.china,
          R.drawable.eur, R.drawable.india, R.drawable.japan,
          R.drawable.libya, R.drawable.swiss, R.drawable.thai, R.drawable.uk,
          R.drawable.us, R.drawable.vietnam };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      button1 = (Button) findViewById(R.id.button1);
      ed1 = (EditText) findViewById(R.id.editText1);
      ed2 = (EditText) findViewById(R.id.editText2);
      ed3 = (EditText) findViewById(R.id.editText3);
      ed4 = (EditText) findViewById(R.id.editText4);
      spinner1 = (Spinner) findViewById(R.id.spinner1);
      spinner2 = (Spinner) findViewById(R.id.spinner2);
      spinner3 = (Spinner) findViewById(R.id.spinner3);
      spinner4 = (Spinner) findViewById(R.id.spinner4);
  
  
  
  
  
  Spinner mySpinner = (Spinner) 
          findViewById(R.id.spinner1); 
  mySpinner.setAdapter(new MyAdapter(this, R.layout.custom_spinner, spinnerValues));  
  
  Spinner mySpinner1 = (Spinner) 
          findViewById(R.id.spinner2); 
  mySpinner1.setAdapter(new MyAdapter(this, R.layout.custom_spinner, spinnerValues));  
  
  Spinner mySpinner2 = (Spinner) 
  findViewById(R.id.spinner3); 
  mySpinner2.setAdapter(new MyAdapter(this, R.layout.custom_spinner, spinnerValues));
  
  Spinner mySpinner3 = (Spinner) 
  findViewById(R.id.spinner4); 
  mySpinner3.setAdapter(new MyAdapter(this, R.layout.custom_spinner, spinnerValues)); 
  
   button1.setOnClickListener(this);
  
  
  
  
    } 
  
   public class MyAdapter extends ArrayAdapter&lt;String&gt; 
   { public MyAdapter(Context ctx, int txtViewResourceId, String[] objects) 
   { super(ctx, txtViewResourceId, objects); } 
  
   @Override
    public View getDropDownView(int position, View cnvtView, ViewGroup prnt) 
   { return getCustomView(position, cnvtView, prnt); }
  
   @Override 
  
  public View getView(int pos, View cnvtView, ViewGroup prnt) 
  { return getCustomView(pos, cnvtView, prnt); } 
  
   public View getCustomView(int position, View convertView, ViewGroup parent)
   { LayoutInflater inflater = getLayoutInflater(); 
   View mySpinner = inflater.inflate(R.layout.custom_spinner, parent, false);
  
    String[] spinnerValues = { "ANGOLAN KWANZA" , "ARGENTINE PESO" , "ARMENIAN DRAM" , "ARUBAN   FLORIN" , "AUSTRALIAN DOLLAR" , "BELARUSIAN RUBLE" , "BOLIVIAN BOLIVIANO" , "BRAZILIAN REAL" , "CAMBODIAN RIEL","CANADIAN DOLLAR","CHINESE YUAN RENMINBI","EURO","INDIAN RUPEE","JAPANESE YEN", "LIBIAN DINAR","SWISS FRANC","THAI BAHT","BRITISH POUND","US DOLLAR","VIETNAMESE DONG"};
  
  
  
      int arr_images[] = { R.drawable.angola, R.drawable.argentina,
      R.drawable.armenia, R.drawable.aruba, R.drawable.australia,
      R.drawable.bielorussia, R.drawable.bolivia, R.drawable.brasil,
      R.drawable.cambodia, R.drawable.canada, R.drawable.china,
      R.drawable.eur, R.drawable.india, R.drawable.japan,
      R.drawable.libya, R.drawable.swiss, R.drawable.thai, R.drawable.uk,
      R.drawable.us, R.drawable.vietnam };
  
      TextView main_text = (TextView) mySpinner .findViewById(R.id.text_main_seen);
      main_text.setText(spinnerValues[position]);
  
       ImageView left_icon = (ImageView) mySpinner .findViewById(R.id.left_pic); 
        left_icon.setImageResource(arr_images[position]); 
       return mySpinner;
  
       }
       public View getCustomView2(int position, View convertView, ViewGroup parent)
      { LayoutInflater inflater = getLayoutInflater(); 
        View mySpinner1 = inflater.inflate(R.layout.custom_spinner, parent, false);
  
        String[] spinnerValues = { "ANGOLAN KWANZA" , "ARGENTINE PESO" , "ARMENIAN DRAM" , "ARUBAN FLORIN" , "AUSTRALIAN DOLLAR" , "BELARUSIAN RUBLE" , "BOLIVIAN BOLIVIANO" , "BRAZILIAN REAL" , "CAMBODIAN RIEL","CANADIAN DOLLAR","CHINESE YUAN RENMINBI","EURO","INDIAN RUPEE","JAPANESE YEN", "LIBIAN DINAR","SWISS FRANC","THAI BAHT","BRITISH POUND","US DOLLAR","VIETNAMESE DONG"};
  
  
  
       int arr_images[] = { R.drawable.angola, R.drawable.argentina,
      R.drawable.armenia, R.drawable.aruba, R.drawable.australia,
      R.drawable.bielorussia, R.drawable.bolivia, R.drawable.brasil,
      R.drawable.cambodia, R.drawable.canada, R.drawable.china,
      R.drawable.eur, R.drawable.india, R.drawable.japan,
      R.drawable.libya, R.drawable.swiss, R.drawable.thai, R.drawable.uk,
      R.drawable.us, R.drawable.vietnam };
  
      TextView main_text = (TextView) mySpinner1 .findViewById(R.id.text_main_seen);
       main_text.setText(spinnerValues[position]);
  
       ImageView left_icon = (ImageView) mySpinner1 .findViewById(R.id.left_pic); 
         left_icon.setImageResource(arr_images[position]); 
       return mySpinner1;}
  
        public View getCustomView3(int position, View convertView, ViewGroup parent)
         { LayoutInflater inflater = getLayoutInflater(); 
        View mySpinner2 = inflater.inflate(R.layout.custom_spinner, parent, false);
  
       String[] spinnerValues = { "ANGOLAN KWANZA" , "ARGENTINE PESO" , "ARMENIAN DRAM" , "ARUBAN FLORIN" , "AUSTRALIAN DOLLAR" , "BELARUSIAN RUBLE" , "BOLIVIAN BOLIVIANO" , "BRAZILIAN REAL" , "CAMBODIAN RIEL","CANADIAN DOLLAR","CHINESE YUAN RENMINBI","EURO","INDIAN RUPEE","JAPANESE YEN", "LIBIAN DINAR","SWISS FRANC","THAI BAHT","BRITISH POUND","US DOLLAR","VIETNAMESE DONG"};
  
  
  
       int arr_images[] = { R.drawable.angola, R.drawable.argentina,
      R.drawable.armenia, R.drawable.aruba, R.drawable.australia,
      R.drawable.bielorussia, R.drawable.bolivia, R.drawable.brasil,
      R.drawable.cambodia, R.drawable.canada, R.drawable.china,
      R.drawable.eur, R.drawable.india, R.drawable.japan,
      R.drawable.libya, R.drawable.swiss, R.drawable.thai, R.drawable.uk,
      R.drawable.us, R.drawable.vietnam };
  
       TextView main_text = (TextView) mySpinner2 .findViewById(R.id.text_main_seen);
       main_text.setText(spinnerValues[position]);
  
         ImageView left_icon = (ImageView) mySpinner2 .findViewById(R.id.left_pic); 
         left_icon.setImageResource(arr_images[position]); 
         return mySpinner2;}
  
        public View getCustomView4(int position, View convertView, ViewGroup parent)
        { LayoutInflater inflater = getLayoutInflater(); 
         View mySpinner3 = inflater.inflate(R.layout.custom_spinner, parent, false);
  
         String[] spinnerValues = { "ANGOLAN KWANZA" , "ARGENTINE PESO" , "ARMENIAN DRAM" , "ARUBAN FLORIN" , "AUSTRALIAN DOLLAR" , "BELARUSIAN RUBLE" , "BOLIVIAN BOLIVIANO" , "BRAZILIAN REAL" , "CAMBODIAN RIEL","CANADIAN DOLLAR","CHINESE YUAN RENMINBI","EURO","INDIAN RUPEE","JAPANESE YEN", "LIBIAN DINAR","SWISS FRANC","THAI BAHT","BRITISH POUND","US DOLLAR","VIETNAMESE DONG"};
  
  
  
      int arr_images[] = { R.drawable.angola, R.drawable.argentina,
      R.drawable.armenia, R.drawable.aruba, R.drawable.australia,
      R.drawable.bielorussia, R.drawable.bolivia, R.drawable.brasil,
      R.drawable.cambodia, R.drawable.canada, R.drawable.china,
      R.drawable.eur, R.drawable.india, R.drawable.japan,
      R.drawable.libya, R.drawable.swiss, R.drawable.thai, R.drawable.uk,
      R.drawable.us, R.drawable.vietnam };
  
      TextView main_text = (TextView) mySpinner3 .findViewById(R.id.text_main_seen);
       main_text.setText(spinnerValues[position]);
  
      ImageView left_icon = (ImageView) mySpinner3 .findViewById(R.id.left_pic); 
      left_icon.setImageResource(arr_images[position]); 
      return mySpinner3;}
  
  
       public boolean onCreateOptionsMenu(Menu menu) {
       getMenuInflater().inflate(R.menu.main, menu);
        return true;
       }
  
  
  
        void getRate(int from, int to) {
          String currency;
         String currency2;
  
  
          currency2 = simbol[from];
  
          int i;
  
       for (i=0;i&lt;=3;i=i+1){
          to=money[i];
           currency=simbol[to];
  
  
  
         GetExchangeRate httpRate;  
         httpRate = new GetExchangeRate(currency, currency2);
          Thread thr = new Thread(httpRate);
          thr.start();
  
         }}}
  
    private void writeRate(final String text) {
     runOnUiThread(new Runnable() {
    @Override
     public void run() {
  
      int i;
  
      for(i=0;i&lt;=3;i=i+1){
          values[i].setText(text); 
  
    }
  }
     });
      }
  
     private String readStream(InputStream in) {
       BufferedReader reader = null;
    StringBuffer response = new StringBuffer();
        try {
     reader = new BufferedReader(new InputStreamReader(in));
       String line = "";
       while ((line = reader.readLine()) != null) {
      response.append(line);
      }
     }
        catch (IOException e) {
        return e.getMessage();
     }
         finally {
         if (reader != null) {
            try {
           reader.close();
    } 
    catch (IOException e) {
      return e.getMessage();
         }
       }
      }
     return response.toString();
     } 
  
     private String transform(String rate) {
     String readableRate = null;
  
     JSONObject json;
      try {
     json = new JSONObject(rate);
     readableRate = " " + json.getDouble("rate");
      }
      catch (JSONException e) {
       readableRate = e.toString();
      } 
       return readableRate;  
      }
  
  
     //**************************************************************************
    //Internal class to call HTTP operation in a separate thread
  
     private class GetExchangeRate implements Runnable {
       String currency;
     String currency2;
  
       GetExchangeRate(String toCurrency, String fromCurrency) {
        currency = toCurrency;
          currency2= fromCurrency;
  
        } 
  
       @Override
       public void run() {
  URL url;
  HttpURLConnection urlConnection = null;
  
  try {
    url = new URL("http://rate-exchange.appspot.com/currency?from=" + currency2 + "&amp;to=" + currency);
    urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setDoInput(true);
    urlConnection.setRequestProperty("Content-Type", "application/json");
    urlConnection.setUseCaches(false);
  
    int responseCode = urlConnection.getResponseCode();
    if(responseCode == HttpStatus.SC_OK) {
      String response = readStream(urlConnection.getInputStream());
      response = transform(response);
      writeRate(response);
    }
    else
      writeRate("Code: " + responseCode);
  }
  catch (Exception e) {
    writeRate(e.toString());
  } 
  finally {
    if(urlConnection != null)
      urlConnection.disconnect();
  
  }
  }
  }
  
  
     @Override
    public void onClick(View v) {
  
  
  
      money1 = Integer.parseInt(String.valueOf(spinner1.getSelectedItemPosition())); 
  money2 = Integer.parseInt(String.valueOf(spinner2.getSelectedItemPosition()));
  money3 = Integer.parseInt(String.valueOf(spinner3.getSelectedItemPosition()));
  money4 = Integer.parseInt(String.valueOf(spinner4.getSelectedItemPosition()));
  
  int[] money = {money1,money2,money3,money4};
  int i;
  
  for(i=0; i&lt;=3;i=i+1)
  
      if(values[i].getText().toString().trim().length() != 0){
  
              from=money[i];
              return;}
  
   }}
  </code></pre>