image123(ImageView) works normal but when it comes to ONclickListener it does not work even after using different methods of Calling the listener.

I put func(),which contain findviewbyid of image123 (ImageView) just after SetContentView() and it works fine .OnclickListener of image123 does not works when func() is in OnClicklistener of Reset Button as Shown in the Code.

Problem:
--------

How can i call the func() in reset button onclicklistener as well as in start at Oncreate() Activity?

It catch an exception shown in Log cat

> 
> **- Exception at Onclick Listener" ,"java.lang.NullPointerException**
> 
> 
> 

```
     public class MainActivity extends Activity {
     ImageView image123;

    int[] resultid=new int[25];

        Button buttonExit;
      Button buttonreset;

            protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     buttonreset=(Button) findViewById(R.id.button_reset);
     buttonExit=(Button) findViewById(R.id.button_exit);

     v1=(TextView)findViewById(R.id.name);
     v2=(TextView)findViewById(R.id.fruit_count);
     //--------------------------Exit Button---------------------------
     buttonExit.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            finish();

        }
    });

    //*******************Exception comes here*********************       
     try{
     image123.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Log.d("Listner Called", "Listner Called");

        }
    });
     }
     catch(Exception e)
     {

         Log.d("Exception at onclickListener", e.toString());

     }

     buttonreset.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

 func();

        }});
}

void func()
{
    String as=null; 
    int resultid;

    SecureRandom random=new SecureRandom();
image123=new ImageView(this);
    as=("img"+1).toString();
    resultid=getResources().getIdentifier(as, "id","com.example.selectiongame"      );
    Log.d(as, ""+resultid);
    image123=(ImageView) findViewById(resultid);

    as="drawable"+(random.nextInt(3)+1);
    resultid = getResources().getIdentifier(as, "drawable", "com.example.selectiongame");
    Log.d(as, ""+resultid);
    image123.setImageResource(resultid);
}

```