1

I know that this question had been asked earlier also but none of them have helped me . What I am trying to do is create a new activity when the user clicks on the marker on a google map . This marker is generated when the user clicks on the OK button of a AlertDialog. And I have made a seperate class as AlertDialogGenerator(which is a non activity class) to create the alertDialog. Now As soon as I click on this marker I get this exception in the logcat:

 java.lang.NullPointerException
    at android.app.Activity.startActivityForResult(Activity.java:3390)
    at android.app.Activity.startActivityForResult(Activity.java:3351)
    at .onMarkerClick(.java:190)
    at com.google.android.gms.maps.GoogleMap$8.a(Unknown Source)
    at com.google.android.gms.maps.internal.k$a.onTransact(Unknown Source)
    at android.os.Binder.transact(Binder.java:347)
    at cni.a(SourceFile:84)
    at maps.af.bj.a(Unknown Source)
    at maps.ao.c.a(Unknown Source)
    at maps.ao.n.c(Unknown Source)
    at maps.ao.m.a(Unknown Source)
    at maps.ao.an.b(Unknown Source)
    at maps.ao.bc.onSingleTapConfirmed(Unknown Source)
    at maps.br.g.onSingleTapConfirmed(Unknown Source)
    at maps.br.i.handleMessage(Unknown Source)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

I know this error has something to do with the context but I dont know what context i have to pass here... I have tried almost every context but none of them works. Here is the code snippet for the intent.

Intent intent = new Intent(contextx,InfoActivity.class);

startActivityForResult(intent, 0);

Here is the code where I am calling the startActivityForResult:

public class Available extends Activity implements
        OnMarkerClickListener {

        private Context contextx;
    public Available(Context context) {
        super();
        this.contextx = context;
    }

    public Available() {
        super();
    }

    public static HashMap<Marker, DriverInfo> driverIdentification;
    private DriverInfo selectedDriverInfo;

    public DriverInfo getSelectedDriverInfo() {
        return selectedDriverInfo;
    }

    public void setSelectedDriverInfo(DriverInfo selectedDriverInfo) {
        this.selectedDriverInfo = selectedDriverInfo;
    }


    @Override
    public boolean onMarkerClick(Marker marker) {



        Intent intent = new Intent(contextx,DriverInfoActivity.class);

        startActivityForResult(intent, 0);

        return false;
    }

}

Contextx is the context of the activity which contains the google map and InfoActivity.class is the class that i want to create onMarker click event. And FYI this intent is created onMarker click event listener.

P.S.- I hope this information is sufficient. If I am missing out at something please leave a comment.

Puneetr90
  • 199
  • 1
  • 6
  • 18

1 Answers1

0

You can do this:

((Activity)contextx).startActivity(i);

Or even this, to keep the startActivityForResult method:

((Activity)contextx).startActivityForResult(intent, 0);

Just tested it and it works.

Curious Mind
  • 659
  • 10
  • 26