开发者

nullpointer exception when clicking on the bubble in the mapview

I'm working on a mapview with a marker. When I click the marker it shows a bubble.

If I click that bubble it shows the toast perfectly.

I want to start the activity there, but it throws an exception.

This is my code:

@Override
protected boolean onBalloonTap(int index) {
try{
Activity a=new Activity();
a.startActivity(new 开发者_Python百科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;
}

My logcat display shows:

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)

What's the problem? I think the problem is the context value. Any ideas or suggestions to resolve this?


The immediate bug is on line 47 in MyItemizedOverlay.java, according to the stack trace.

And, you can't just create a new Activity like that. You need a real Context (such as the activity containing the MapView, or the application context) in order to start an activity.

Also, a side comment: where is onBalloonTap defined? It doesn't seem to be a standard ItemizedOverlay method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜