title: How to start Activity from java class in Android
body: <p>Here is the code. </p>
  
  <pre><code>public class MyActivity extends Activity {
  
    @Override
    public void onCreate(Bundle bundle) {
      super.onCreate(bundle);
  
      MyClass myClass = new MyClass(this);
      Cursor cursor = myClass.getCursor();
      startManagingCursor(cursor);
    }
  }
  
  public class MyClass Extends ImageButton { 
  
    private Context context;
  
    public MyClass(Context context) {
      this.context = context;
    }
  
    public Cursor getOncreate() {
       Intent intent = new Intent();
           intent.setClassName(MyClass.this,MyActivity.class);
          context.startActivity(intent);    
    }
  }
  </code></pre>
  
  <p>I want to start MyActivity from MyClass. I am getting NullPointer exception at </p>
  
  <pre><code>ctx.startActvity(intent);
  </code></pre>
  
  <p>Could you please suggest me how to make it correct.</p>