Im calling a poup dialog from a menu option that says sign in with: then shows Twitter and Google logos as 2 imagebuttons.

```
AlertDialog.Builder alertadd = new AlertDialog.Builder(
            SummaryActivity.this);
    LayoutInflater factory = LayoutInflater.from(SummaryActivity.this);
    final View view = factory.inflate(R.layout.social_network_selection, null);
    alertadd.setView(view);

```

It inflates a view that contains the 2 imagebuttons.

when i add the code 

```
    googleButton2 = (ImageButton)findViewById(R.id.googleButton);
    twitterButton2 = (ImageButton)findViewById(R.id.twitterButton);

```

All works fine but when i add the

```
googleButton2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

           Toast.makeText(MyAndroidAppActivity.this,
            "googleButton2 is clicked!", Toast.LENGTH_SHORT).show();

        }

    });

```

It crashes with a null pointer. Not when i click the button but the second i call the AlertDialog that contains the ImageButtons

How do you add a listener to an imagebutton that is on an AlertDialog inflated View?

LOGCAT

```
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at android.support.v7.internal.view.SupportMenuInflater$InflatedOnMenuItemClickListener.onMenuItemClick(SupportMenuInflater.java:259)
        at android.support.v7.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
        at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
        at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)
        at android.support.v7.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:191)

```