0

I have a MapView in my app. On clicking an overlayItem, a bubble pops-up with information about the place.On clicking the icon, the user should go to another activity.

I first send the control from inside the

BalloonItemizedOverlay<OverlayItem>.MapBalloonItemizedOverlay.onBalloonTap(int index, OverlayItem item)

method to the MainActivity page using:

MainActivityObject.gotoMethod();

i.e

@Override
public boolean onBalloonTap(int index, OverlayItem item)
{
   MainActivityObject.gotoMethod();
    return true;
}

Then in that method I code:

try
    {
    Intent goIntent = new Intent(MainActivity.this, NextActivity.class);
    startActivity(goIntent);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

But I get the below null-pointer exception error:

09-19 16:02:56.707: WARN/System.err(2454): java.lang.NullPointerException
09-19 16:02:56.717: WARN/System.err(2454):     at android.content.ContextWrapper.getPackageName(ContextWrapper.java:120)
09-19 16:02:56.717: WARN/System.err(2454):     at android.content.ComponentName.<init>(ComponentName.java:75)
09-19 16:02:56.717: WARN/System.err(2454):     at android.content.Intent.<init>(Intent.java:2678)
09-19 16:02:56.717: WARN/System.err(2454):     at towerCo.Android.Main.MapsActivity.showDetailpage(MapsActivity.java:897)
09-19 16:02:56.717: WARN/System.err(2454):     at towerCo.Android.MapOverLays.MapBalloonItemizedOverlay.onBalloonTap(MapBalloonItemizedOverlay.java:55)
09-19 16:02:56.717: WARN/System.err(2454):     at mapViewBalloon.BalloonItemizedOverlay$1.onTouch(BalloonItemizedOverlay.java:169)
09-19 16:02:56.717: WARN/System.err(2454):     at android.view.View.dispatchTouchEvent(View.java:3762)
09-19 16:02:56.727: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
09-19 16:02:56.727: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.727: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.727: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.727: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.727: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.727: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.727: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.727: WARN/System.err(2454):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
09-19 16:02:56.727: WARN/System.err(2454):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
09-19 16:02:56.727: WARN/System.err(2454):     at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
09-19 16:02:56.738: WARN/System.err(2454):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
09-19 16:02:56.738: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.738: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.738: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.738: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.738: WARN/System.err(2454):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
09-19 16:02:56.738: WARN/System.err(2454):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
09-19 16:02:56.747: WARN/System.err(2454):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
09-19 16:02:56.747: WARN/System.err(2454):     at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
09-19 16:02:56.747: WARN/System.err(2454):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
09-19 16:02:56.747: WARN/System.err(2454):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
09-19 16:02:56.747: WARN/System.err(2454):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 16:02:56.747: WARN/System.err(2454):     at android.os.Looper.loop(Looper.java:123)
09-19 16:02:56.747: WARN/System.err(2454):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-19 16:02:56.747: WARN/System.err(2454):     at java.lang.reflect.Method.invokeNative(Native Method)
09-19 16:02:56.747: WARN/System.err(2454):     at java.lang.reflect.Method.invoke(Method.java:521)
09-19 16:02:56.747: WARN/System.err(2454):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-19 16:02:56.747: WARN/System.err(2454):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-19 16:02:56.747: WARN/System.err(2454):     at dalvik.system.NativeStart.main(Native Method)
animuson
  • 53,861
  • 28
  • 137
  • 147
Ahmed Faisal
  • 4,397
  • 12
  • 45
  • 74
  • It looks like it's the Intent constructor that's blowing up from a function called showDetailpage. Can you post that code? Is that where the gotoMethod is being called from? – brianestey Sep 19 '11 at 16:26
  • Thank for the comment. I have updated the comment.I also read somewhere that I need to directly access the activity that contains my MapView and not create a new MainActivity Object.Please advise. – Ahmed Faisal Sep 19 '11 at 16:32
  • Does `MainActivityObject` extend `Activity`? How do you instantiate it? – Peter Knego Sep 19 '11 at 17:12
  • I am not sure!I used MainActivity MainActivityObject =new MainActivityObject(); – Ahmed Faisal Sep 19 '11 at 18:55
  • Check the class definition, ie. `public class MainActivity extends Activity` ? – brianestey Sep 20 '11 at 05:20

1 Answers1

1

I think I have found the answer in another post.I will repost it here for others:

Mapview start new activity when a baloonOverlay is clicked

Replace this:

MainActivity MainActivityObject = new MainActivity (); 
sub.startCustomActivity(); 

with this:

Intent Details = new Intent(context, Tab.class); 
context.startActivity(Details); 

So we basically have to use the context variable we got from the MapView passed in our overlay class to start our activity.

Thank You to all for helping me earlier. Appreciated!

Community
  • 1
  • 1
Ahmed Faisal
  • 4,397
  • 12
  • 45
  • 74