2011-05-04 114 views
0

我有一個方法可以在水龍頭上創建彈出式對話框,稱爲onBalloonTap,我試圖在另一個類pip中調用CallPopup()。我究竟做錯了什麼?我不應該通過方法調用intent嗎?我的目標是在調用onBalloonTap時啓動另一項活動。有一個更好的方法嗎?Android從另一個類中的方法調用一個Intent

pip

public void CallPopup() 
{ Log.i("CallPopup", "Started CallPopup"); 
    startActivity(intent); 
    finish(); 
} 

CallPopUp()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

它看起來像「pip」類擴展了Activity,但您只是在不經歷任何Activity生命週期的情況下創建pip對象。空指針異常可能是因爲你的pip對象不知道它的父上下文是什麼。您幾乎可以肯定可以訪問onBalloonTap中的Context對象(例如,View.getContext()),那麼爲什麼不直接從那裏調用Context.startActivity()

0

您需要聲明intent你使用0 這可能是你得到NullPointerException的原因。

相關問題