我正在使用标记处理mapview。当我点击标记时,它会显示一个气泡。
如果我点击那个气泡,就会完美地显示吐司。
我想在那里开始活动,但它会引发异常。
这是我的代码:
@Override
protected boolean onBalloonTap(int index) {
try{
Activity a=new Activity();
a.startActivity(new Intent(a.getBaseContext(),BruConnect_Detail.class));
// Toast.makeText(c, "onBalloonTap for overlay index " + index,
// Toast.LENGTH_LONG).show();
}catch(Exception e){
Log.v(TAG,"error:"+e);
e.printStackTrace();
}
return true;
}
我的logcat显示屏显示:
03-04 23:53:13.311: VERBOSE/MyItemizedOverlay(713): error:java.lang.NullPointerException
03-04 23:53:13.322: WARN/System.err(713): java.lang.NullPointerException
03-04 23:53:13.331: WARN/System.err(713): at android.content.ComponentName.<init>(ComponentName.java:75)
03-04 23:53:13.331: WARN/System.err(713): at android.content.Intent.<init>(Intent.java:2551)
03-04 23:53:13.352: WARN/System.err(713): at com.example.bruconnect.MyItemizedOverlay.onBalloonTap(MyItemizedOverlay.java:47)
03-04 23:53:13.352: WARN/System.err(713): at com.example.bruconnect.BalloonItemizedOverlay$1.onTouch(BalloonItemizedOverlay.java:135)
03-04 23:53:13.373: WARN/System.err(713): at android.view.View.dispatchTouchEvent(View.java:3705)
03-04 23:53:13.373: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
03-04 23:53:13.382: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.392: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.402: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.402: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.411: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.424: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.431: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.462: WARN/System.err(713): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
03-04 23:53:13.474: WARN/System.err(713): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
03-04 23:53:13.482: WARN/System.err(713): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
03-04 23:53:13.482: WARN/System.err(713): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
03-04 23:53:13.502: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.502: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.512: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.525: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.525: WARN/System.err(713): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-04 23:53:13.525: WARN/System.err(713): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
03-04 23:53:13.533: WARN/System.err(713): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
03-04 23:53:13.542: WARN/System.err(713): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
03-04 23:53:13.552: WARN/System.err(713): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
03-04 23:53:13.552: WARN/System.err(713): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
03-04 23:53:13.562: WARN/System.err(713): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 23:53:13.562: WARN/System.err(713): at android.os.Looper.loop(Looper.java:123)
03-04 23:53:13.562: WARN/System.err(713): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-04 23:53:13.581: WARN/System.err(713): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 23:53:13.581: WARN/System.err(713): at java.lang.reflect.Method.invoke(Method.java:521)
03-04 23:53:13.591: WARN/System.err(713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-04 23:53:13.601: WARN/System.err(713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-04 23:53:13.601: WARN/System.err(713): at dalvik.system.NativeStart.main(Native Method)
有什么问题?我认为问题在于背景值。有任何想法或建议可以解决这个问题吗?
答案 0 :(得分:1)
根据堆栈跟踪,直接错误在MyItemizedOverlay.java
的第47行上。
而且,你不能像这样创建一个新的Activity
。您需要一个真实的Context
(例如包含MapView
的活动或应用程序上下文)才能开始活动。
另外,旁注:onBalloonTap
定义在哪里?它似乎不是标准的ItemizedOverlay
方法。