我有一个方法可以点击创建弹出窗口,名为onBalloonTap
,我正在尝试在另一个班级CallPopup()
中调用pip
。我究竟做错了什么?我不应该通过方法调用意图吗?我的目标是在调用onBalloonTap
时启动另一个活动。有更好的方法吗?
CallPopUp()
中的 pip
public void CallPopup()
{ Log.i("CallPopup", "Started CallPopup");
startActivity(intent);
finish();
}
从另一个班级的onBalloonTap
调用
protected boolean onBalloonTap(int index, OverlayItem item) {
Toast.makeText(c, "onBalloonTap for overlay index " + index,
Toast.LENGTH_LONG).show();
pip pipinst =new pip();
pipinst.CallPopup();
return true;
}
我得到这个日志:
05-04 22:33:41.022: ERROR/AndroidRuntime(704): FATAL EXCEPTION: main
05-04 22:33:41.022: ERROR/AndroidRuntime(704): java.lang.NullPointerException
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.app.Activity.startActivityForResult(Activity.java:2817)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.app.Activity.startActivity(Activity.java:2923)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at com.appname.pip.pip.CallPopup(pip.java:192)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at com.appname.pip.MyItemizedOverlay.onBalloonTap(MyItemizedOverlay.java:67)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay$1.onTouch(BalloonItemizedOverlay.java:203)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.view.View.dispatchTouchEvent(View.java:3762)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.os.Looper.loop(Looper.java:123)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at java.lang.reflect.Method.invoke(Method.java:521)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-04 22:33:41.022: ERROR/AndroidRuntime(704): at dalvik.system.NativeStart.main(Native Method)
05-04 22:33:41.102: WARN/ActivityManager(38): Force finishing activity com.appname.pip/.pip
05-04 22:33:41.952: WARN/ActivityManager(38): Activity pause timeout for HistoryRecord{43f680f0 com.appname.pip/.pip}
答案 0 :(得分:0)
您需要在intent
中声明您使用的CallPopup()
这可能是您获得NullPointerException
的原因。
答案 1 :(得分:0)
看起来“pip”类扩展了Activity,但你只是在不经过任何Activity生命周期的情况下创建一个pip对象。空指针异常可能是因为你的pip对象不知道它的父Context是什么。您几乎肯定可以访问onBalloonTap中的Context对象(例如,View.getContext()),那么为什么不从那里调用Context.startActivity()呢?