title: Adding Huge Canvas in the ScrollView in Android
body: <p>In my android application, I want to add a huge canvas in a <code>scrollView</code> because if I draw a huge line I need to see with scrolling option.</p>
  
  <p>But I am getting error in LogCat:</p>
  
  <blockquote>
    <p>01-01 11:42:14.452: E/AndroidRuntime(1706): java.lang.RuntimeException: Unable to start 
    activity ComponentInfo{com.example.list2/com.example.list2.MainActivity}: 
    java.lang.NullPointerException</p>
  </blockquote>
  
  <h2>layout</h2>
  
  <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:paddingLeft="16dp"
     android:paddingRight="16dp" &gt;
         &lt;View
          android:id="@+id/mapview1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" /&gt;     
  &lt;/ScrollView&gt;
  </code></pre>
  
  <h2>activity</h2>
  
  <pre><code>package com.example.list2;
  
  import android.app.Activity;
  import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ScrollView;
  
  public class MainActivity extends Activity{
      Map map;
      public void onCreate(Bundle saved){
          super.onCreate(saved);
          setContentView(R.layout.activity_main);  
  
          ScrollView scrollView = new ScrollView(this);
          scrollView.addView(map);
          setContentView(scrollView);  
      }
  
  
      public void Draw(){
          map = new Map(this);
          map.setBackgroundColor(Color.BLACK);
          setContentView(map);
      }
  
  
      public class Map extends View {
          Paint paint = new Paint();
  
          public Map(Context context) {
              super(context);
          }
  
  
          @Override
          public void onDraw(Canvas canvas) {
              paint.setColor(Color.RED);
              canvas.drawCircle(100, 100, 20, paint);
              canvas.drawLine(2000, 2000, 5000, 5000, paint);
  
          }
  
          @Override
          protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
              // Compute the height required to render the view
              // Assume Width will always be MATCH_PARENT.
              int width = MeasureSpec.getSize(widthMeasureSpec);
              int height = 3000 + 50; // Since 3000 is bottom of last Rect to be drawn added and 50 for padding.
              setMeasuredDimension(width, height);
          }
      }
  
  }
  </code></pre>