我有以下内部活动的活动
public class Closer extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
doMyWork();
}
public void gotoCat() {
Intent intent = new Intent(this, CatActivity.class);
startActivityForResult(intent, 1);
}
}
但是当我运行代码时,我得到了一个根植于该行的 NPE startActivityForResult(intent, 1)
。我将如何成功地做到这一点?
来自封闭活动的调用是new Closer.gotoCat()
错误:
java.lang.NullPointerException
at android.app.Activity.startActivityForResult(Activity.java:3430)
at android.app.Activity.startActivityForResult(Activity.java:3391)
at com.company.Game.widget.MyView$Closer.gotoCat(MyView.java:496)
at com.company.Game.widget.MyView.onDragEndSoCallCat(MyView.java:315)
at com.company.Game.widget.MyView.onTouch(MyView.java:254)
at android.view.View.dispatchTouchEvent(View.java:7456)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2264)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1995)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)