title: ClassCastException with no debuggable errors
body: <p>I am trying to create an object of fingerline(class) in drawline(activity).The fingerline takes the context of MainActivity(activity).I get ClassCastException showing that</p>
  <pre><code>    Process: com.example.caddrawingtool, PID: 11405
      java.lang.RuntimeException: Unable to instantiate application 
      com.example.caddrawingtool.MainActivity: java.lang.ClassCastException: 
      com.example.caddrawingtool.MainActivity cannot be cast to android.app.Application
      at android.app.LoadedApk.makeApplication(LoadedApk.java:1226)
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6504)
      at android.app.ActivityThread.access$1400(ActivityThread.java:229)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1892)
      at android.os.Handler.dispatchMessage(Handler.java:107)
      at android.os.Looper.loop(Looper.java:214)
      at android.app.ActivityThread.main(ActivityThread.java:7436)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
  </code></pre>
  <p>I have changed getApplicationContext() in drawline where the fingerline object was created to Activity context by using</p>
  <pre><code>  this    
  </code></pre>
  <p>I am not able to use</p>
  <pre><code>        MainActivity.this
  </code></pre>
  <p>though.</p>
  <p>Is there a way to simplify all this?
  My MainActivity code:</p>
  <pre><code>    public class MainActivity extends AppCompatActivity {
  fingerline dv;
  private Paint mpaint;
  private Context context;
  MainActivity MainActivity(){
      return MainActivity.this;
  
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
      dv = new fingerline(this);
      setContentView(dv);
     
      dv.setBackgroundColor(Color.BLACK);
      mpaint = new Paint();
      mpaint.setAntiAlias(true);
      mpaint.setDither(true);
      mpaint.setColor(Color.WHITE);
      mpaint.setStyle(Paint.Style.STROKE);
      mpaint.setStrokeJoin(Paint.Join.MITER);
      mpaint.setStrokeCap(Paint.Cap.ROUND);
      mpaint.setStrokeWidth(12);
      getSupportActionBar().setTitle(&quot;3D TOOL&quot;);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  }
  
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.my_menu, menu);
  
      return super.onCreateOptionsMenu(menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(@NonNull MenuItem item) {
      int id = item.getItemId();
      switch (id) {
          case R.id.line:
              Intent intent = new Intent(this, drawline2.class);
              intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              this.startActivity(intent);
  
              break;
          case R.id.circle:
              Intent intent1=new Intent(this,drawcircle.class);
              intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              this.startActivity(intent1);
  
              break;
          case R.id.rectangle:
              Intent intent2=new Intent(this,drawrectangle.class);
              intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              this.startActivity(intent2);
              break;
          case R.id.offset:
  
              break;
          default:
              break;
  
      }
      return super.onOptionsItemSelected(item);
  
  }
  </code></pre>
  <p>My fingerline code:</p>
  <pre><code>  public class fingerline extends View {
  public int width, height;
  private Bitmap mbitmap;
  private Canvas mcanvas;
  private Paint mpaint, mbitmappaint, circlepaint;
  private float startx;
  private float starty;
  private float endx;
  private float endy;
  private Path path, circlepath;
  Context c;
  
  public fingerline(Context context) {
      super(context);
    //  c = context;
      path = new Path();
      mpaint = new Paint();
      mbitmappaint = new Paint(Paint.DITHER_FLAG);
      circlepaint = new Paint();
      circlepath = new Path();
      circlepaint.setAntiAlias(true);
      circlepaint.setColor(Color.WHITE);
      circlepaint.setStyle(Paint.Style.STROKE);
      circlepaint.setStrokeJoin(Paint.Join.MITER);
      circlepaint.setStrokeWidth(4f);
  }
  
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
      super.onSizeChanged(w, h, oldw, oldh);
      mbitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
      mcanvas = new Canvas(mbitmap);
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      mpaint.setStyle(Paint.Style.STROKE);
      mpaint.setColor(Color.WHITE);
      mpaint.setStrokeWidth(12);
      mpaint.setAntiAlias(true);
      mpaint.setDither(true);
      mpaint.setStrokeJoin(Paint.Join.MITER);
      mpaint.setStrokeCap(Paint.Cap.ROUND);
      canvas.drawBitmap(mbitmap, 0, 0, mbitmappaint);
      canvas.drawPath(path, mpaint);
      canvas.drawPath(circlepath, circlepaint);
  }
  
  private float mX, mY;
  private static final float TOUCH_TOLERANCE = 4;
  
  private void touch_start(float x, float y) {
      path.reset();
      path.moveTo(x, y);
      mX = x;
      mY = y;
  }
  
  private void touch_move(float x, float y) {
      float dX = Math.abs(x - mX);
      float dY = Math.abs(y - mY);
      if (dX &gt;= TOUCH_TOLERANCE) {
          path.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
          mX = x;
          mY = y;
      }
  }
  
  private void touch_up() {
      path.lineTo(mX, mY);
      circlepath.reset();
      mcanvas.drawPath(path, mpaint);
      path.reset();
  }
  
  @SuppressLint(&quot;ClickableViewAccessibility&quot;)
  @Override
  public boolean onTouchEvent(MotionEvent event) {
      switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN:
              startx = event.getX();
              starty = event.getY();
              touch_start(startx, starty);
              invalidate();
              break;
          case MotionEvent.ACTION_MOVE:
              startx = event.getX();
              starty = event.getY();
              touch_move(startx, starty);
              invalidate();
              break;
          case MotionEvent.ACTION_UP:
              touch_up();
              invalidate();
              break;
  
      }
      return true;
  
  }
  </code></pre>
  <p>}</p>
  <p>My drawline code:</p>
  <pre><code>public class drawline2 extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_drawline2);
      Toolbar toolbar = findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      EditText editText, editText1;
      editText = (EditText) findViewById(R.id.length);
      editText1 = (EditText) findViewById(R.id.angle);
      Canvas canvas;
      Paint paint = new Paint();
      Paint circlepaint = new Paint();
      Path path = new Path();
      Path cpath = new Path();
      circlepaint.setAntiAlias(true);
      circlepaint.setStrokeWidth(4f);
      circlepaint.setColor(Color.WHITE);
      circlepaint.setStyle(Paint.Style.STROKE);
      circlepaint.setStrokeJoin(Paint.Join.MITER);
      fingerline dv;
      dv = new fingerline(this);
      dv.setBackgroundColor(Color.BLACK);
      setContentView(dv);
      circlepaint.setAntiAlias(true);
      circlepaint.setDither(true);
      String value = editText.getText().toString();
      int length =0;
      double angle=0;
      if(value!=null &amp;&amp; value.length()&gt;0){
          try{
              length = Integer.parseInt(value);
  
          }
          catch (NullPointerException e){
              length=0;
          }
      }
  
      String value1 = editText1.getText().toString();
      if(value1!=null &amp;&amp; value1.length()&gt;0){
          try{
              angle = Double.parseDouble(value1);
          }
          catch (NullPointerException e){
              angle=0;
          }
      }
  
  
      int startX, startY, endX, endY, x, y;
      x= 0;
      y=0;
      path.reset();
      path.moveTo(x, y);
      startX = (int) x;
      startY = (int) y;
  
      endY = (int) (x + length * Math.cos(angle));
      endX = (int) (x + length * Math.sin(angle));
  
  
      FloatingActionButton fab = findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Snackbar.make(view, &quot;Replace with your own action&quot;, Snackbar.LENGTH_LONG)
                      .setAction(&quot;Action&quot;, null).show();
  
          }
  
      });
  }
  </code></pre>
  <p>}
  Thanks in advance.</p>