title: ImageView findViewById and setContent(R.layout.main) doesn't work
body: <p>I have a problem with this simple code. I'm trying everything possible, but setContent(R.layout.main) always causes an error. If I tried debug code svgView = (SVGView)findViewById(R.id.svgview) value was always null.  </p>
  
  <p>This is my code:</p>
  
  <p>SVGViewActivity.java :</p>
  
  <pre><code>    package android.svgview;
  
      import com.larvalabs.svgandroid.SVG;
      import com.larvalabs.svgandroid.SVGParser;
  
      import android.app.Activity;
      import android.graphics.Color;
      import android.os.Bundle;
  
      public class SVGViewActivity extends Activity {
          /** Called when the activity is first created. */
  
      private SVGView svgView;
      private ViewListener viewListener;
      private ViewState viewState;
      private SVG svg;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          svgView = (SVGView)findViewById(R.id.svgview);
          viewListener = new ViewListener();
          viewState = new ViewState();
  
          svgView.setViewState(viewState);
          svgView.setOnTouchListener(viewListener);
          viewListener.setViewState(viewState);
  
          svg = SVGParser.getSVGFromResource(getResources(), R.drawable.android);
          svgView.setImageDrawable(svg.createPictureDrawable());
          svgView.setBackgroundColor(Color.WHITE);
  
      }
  }
  </code></pre>
  
  <p>SVGView.java</p>
  
  <pre><code>package android.svgview;
  
  import java.util.Observable;
  import java.util.Observer;
  
  import android.content.Context;
  import android.graphics.Canvas;
  import android.widget.ImageView;
  
  public class SVGView extends ImageView implements Observer {
  
      private ViewState viewState;
  
      public SVGView(Context context) {
          super(context);
      }
  
      public void setViewState(ViewState viewState){
          if(this.viewState==null){
              this.viewState = viewState;
              this.viewState.addObserver(this);
          }
      }
  
      protected void onDraw(Canvas canvas){
  
          canvas.scale(1.0f, 1.0f);
          canvas.translate(viewState.getX(), viewState.getY());
  
          super.onDraw(canvas);
  
      }
      public void update(Observable observable, Object data) {
          invalidate();
  
      }
  }
  </code></pre>
  
  <p>and main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;android.svgview.SVGView
          android:id="@+id/svgview" 
          /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>When I change <code>svgView = (SVGView)findViewById(R.id.svgview);</code> for <code>svgView = new SVGView(this);</code> and then <code>setContentView(R.layout.main);</code> for <code>setContentView(svgView);</code> everything works fine. But using main.xml causes errors.</p>
  
  <p>I tried clean and recompile project, compile it in new eclipse instalation with all updates but no effect. I have no idea where is a problem :-/</p>