title: Strange ClassCastException:android.widget.textview
body: <p>I am using google currency api to convert currencies.But I am encountering a strange class cast exception and cannot figure out what is happening.</p>
  
  <p>I am posting the entire xml:</p>
  
  <p>
  </p>
  
  <pre><code>&lt;include
      android:id="@+id/footer"
      layout="@layout/footer" /&gt;
  
  &lt;include
      android:id="@+id/header"
      layout="@layout/header" /&gt;
  
  &lt;ScrollView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@id/footer"
      android:layout_below="@id/header" &gt;
  
      &lt;RelativeLayout
          android:id="@+id/rlbody"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="18dp"
          android:background="#ffffff" &gt;
  
          &lt;RelativeLayout
              android:id="@+id/rlfrom"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="15dp" &gt;
  
              &lt;Spinner
                  android:id="@+id/from_currency"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/txtfromtext"
                  android:background="@drawable/spinner_bg" /&gt;
  
           &lt;TextView
                  android:id="@+id/txtfromtext"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:layout_centerHorizontal="true"
                  android:text="From Currency:"
                  android:textSize="18sp"
                  android:textStyle="bold" /&gt; 
          &lt;/RelativeLayout&gt;
  
          &lt;RelativeLayout
              android:id="@+id/rlto"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@+id/rlfrom"
              android:layout_marginTop="20dp" &gt;
  
              &lt;TextView
                  android:id="@+id/txttotext"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_centerHorizontal="true"
                  android:text="To Currency:"
                  android:textSize="18sp"
                  android:textStyle="bold" /&gt; 
  
              &lt;Spinner
                  android:id="@+id/to_currency"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/txttotext"
                  android:background="@drawable/spinner_bg" /&gt;
          &lt;/RelativeLayout&gt;
  
          &lt;RelativeLayout
              android:id="@+id/rlexchangeamt"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_below="@+id/rlto"
              android:layout_marginTop="20dp" &gt;
  
              &lt;TextView
                  android:id="@+id/txtamt"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_centerHorizontal="true"
                  android:text="Exchange Amount:"
                  android:textSize="18sp"
                  android:textStyle="bold" /&gt;
  
              &lt;EditText
                  android:id="@+id/input_amount"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/txtamt"
                  android:layout_margin="3dp"
                  android:background="@drawable/editbackground"
                  android:gravity="center" /&gt;
          &lt;/RelativeLayout&gt;
  
          &lt;LinearLayout
              android:id="@+id/lv_button"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_below="@+id/rlexchangeamt"
              android:orientation="horizontal"
              android:weightSum="1" &gt;
  
              &lt;Button
                  android:id="@+id/convert"
                  android:layout_width="30dp"
                  android:layout_height="wrap_content"
                  android:layout_margin="10dp"
                  android:layout_weight="0.5"
                  android:background="#9d1515"
                  android:padding="12dp"
                  android:text="Calculate"
                  android:textColor="#ffffff"
                  android:textSize="18sp"
                  android:textStyle="bold" /&gt;
  
              &lt;Button
                  android:id="@+id/clear_input"
                  android:layout_width="30dp"
                  android:layout_height="wrap_content"
                  android:layout_margin="10dp"
                  android:layout_weight="0.5"
                  android:background="#181818"
                  android:padding="12dp"
                  android:text="Reset"
                  android:textColor="#ffffff"
                  android:textSize="18sp"
                  android:textStyle="bold" /&gt;
          &lt;/LinearLayout&gt;
  
          &lt;TextView
              android:id="@+id/output_amount"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_below="@+id/lv_button"
              android:layout_marginTop="10dp"
              android:gravity="center"
              android:paddingBottom="5dp"
              android:paddingRight="5dp"
              android:paddingTop="5dp"
              android:text="hello"
              android:textColor="#9d1515"
              android:textSize="20sp"
              android:textStyle="bold" /&gt;
      &lt;/RelativeLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>The irony:</strong> The <strong>classcast</strong> exception <strong>is showing only after I have inserted the scrollview</strong>.Before that every thing was fine.</p>
  
  <p>Relevant code:</p>
  
  <pre><code>public class CurrencyConverterActivity extends Activity implements
  OnClickListener, OnItemSelectedListener, TextWatcher {
      private static final String TAG = "UnitConverterActivity";
      TextView tvheader;
      private Spinner fromCurrency;
      private Spinner toCurrency;
      private EditText inputAmount;
      private TextView outputAmount, tv_header;
      private View convert;
      private View reverseCurrencies;
      private View clearInput;
      private CurrencyConverter currencyConverter;
      Activity mBaseActivity;
      String namearray[];
      List&lt;Currency&gt; curr ;
       String fromcode,tocode;
       ImageButton btnback;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
          WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.currency_converter);
          btnback=(ImageButton)findViewById(R.id.btn_back);
          btnback.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent i=new Intent(CurrencyConverterActivity.this,MainActivity.class);
                  startActivity(i);
                  finish();
              }
          });
          tvheader=(TextView)findViewById(R.id.tv_pagetitle);
          tvheader.setText("Currency Converter");
          Bitmap bmp = BitmapFactory.decodeResource(getResources(),     R.drawable.pattern_bg);
          BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
          bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
          RelativeLayout rl = (RelativeLayout)findViewById(R.id.rl_main);
          rl.setBackgroundDrawable(bitmapDrawable);
              curr = new ArrayList&lt;Currency&gt;();
      //A     
              curr.add(new Currency("United Arab Emirates Dirham(AED)","AED"));
              curr.add(new Currency("Afghan Afghani(AFN)","AFN"));
              curr.add(new Currency("Albanian Lek(ALL)","ALL"));
              curr.add(new Currency("Armenia Dram(AMD)","AMD"));
              curr.add(new Currency("Netherlands Antilles Guilder(ANG)","ANG"));
              curr.add(new Currency("Angola Kwanza(AOA)","AOA"));
              curr.add(new Currency("Argentina Peso(ARS)","ARS"));
              curr.add(new Currency("Australia Dollar(AUD)","AUD"));
              curr.add(new Currency("Aruba Guilder(AWG)","AWG"));
  
  
  
  
  
            namearray=new String[curr.size()];
            for(int i=0;i&lt;curr.size();i++)  
            {  
              Currency item = curr.get(i);
              namearray[i]=item.getName();
            }
  
              ArrayAdapter&lt;String&gt; adapter=new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item,namearray);
              adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
  
  
          this.fromCurrency = (Spinner) super.findViewById(R.id.from_currency);
          this.fromCurrency.setOnItemSelectedListener(this);
          fromCurrency.setAdapter(adapter);
  
  
  
          this.toCurrency = (Spinner) super.findViewById(R.id.to_currency);
          this.toCurrency.setOnItemSelectedListener(this);
          toCurrency.setAdapter(adapter);
  
  
          this.inputAmount = (EditText) super.findViewById(R.id.input_amount);
          this.inputAmount.setText("1");
          this.inputAmount.addTextChangedListener(this);
  
          this.outputAmount = (TextView) super.findViewById(R.id.output_amount);
  
          this.convert = super.findViewById(R.id.convert);
          this.convert.setOnClickListener(this);
  
  
          this.clearInput = super.findViewById(R.id.clear_input);
          this.clearInput.setOnClickListener(this);
  
  
          this.currencyConverter = new GoogleCurrencyConverter();
      }
  </code></pre>
  
  <p>LogCat:</p>
  
  <pre><code>09-23 10:43:50.876: E/AndroidRuntime(1693): FATAL EXCEPTION: main
  09-23 10:43:50.876: E/AndroidRuntime(1693): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.webguru.calculatorapp/com.webguru.calculatorapp.CurrencyConverterActivity}: java.lang.ClassCastException: android.widget.TextView
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1740)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1759)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at android.app.ActivityThread.access$1500(ActivityThread.java:155)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:999)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at android.os.Handler.dispatchMessage(Handler.java:130)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at android.os.Looper.loop(SourceFile:351)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at android.app.ActivityThread.main(ActivityThread.java:3826)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at java.lang.reflect.Method.invokeNative(Native Method)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at java.lang.reflect.Method.invoke(Method.java:538)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at dalvik.system.NativeStart.main(Native Method)
  09-23 10:43:50.876: E/AndroidRuntime(1693): Caused by: java.lang.ClassCastException: android.widget.TextView
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at com.webguru.calculatorapp.CurrencyConverterActivity.onCreate(CurrencyConverterActivity.java:373)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1704)
  09-23 10:43:50.876: E/AndroidRuntime(1693):     ... 11 more
  </code></pre>
  
  <p><strong>Line Number 373:this.toCurrency = (Spinner) super.findViewById(R.id.to_currency);</strong></p>
  
  <p>I have absolutely no idea what wrong I am doing here.Help.</p>