App is crashing when i try to implement onClickListener : <p>Im making ViewPager with buttons.
Im trying to get the id of button and set onclicklistener to that button in viewpager class.</p>

<p>I have one problem.
I tried something like this ` </p>

<pre><code>Button btn1 = (Button) findViewById(R.id.gimnazijablbtn1);

btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                switch(v.getId()) {

                    case R.id.gimnazijablbtn1:
                        Intent Banjaluka = new Intent(banjaluka_activity.this,PocetniActivity.class);
                        startActivity(Banjaluka);
                        break;
                }

            }
        });`
</code></pre>

<p>But my app is crashing.</p>

<p>Here is the log
<code>04-24 20:46:42.574 24297-24297/com.electroniccode.ln.vodickrozzanimanja E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                          Process: com.electroniccode.ln.vodickrozzanimanja, PID: 24297
                                                                                          java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.electroniccode.ln.vodickrozzanimanja/com.electroniccode.ln.vodickrozzanimanja.banjaluka_activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
                                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
                                                                                              at android.app.ActivityThread.access$900(ActivityThread.java:157)
                                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
                                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                              at android.os.Looper.loop(Looper.java:148)
                                                                                              at android.app.ActivityThread.main(ActivityThread.java:5551)
                                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
                                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
                                                                                           Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                                                              at android.support.v7.app.AppCompatDelegateImplBase.&lt;init&gt;(AppCompatDelegateImplBase.java:117)
                                                                                              at android.support.v7.app.AppCompatDelegateImplV9.&lt;init&gt;(AppCompatDelegateImplV9.java:149)
                                                                                              at android.support.v7.app.AppCompatDelegateImplV11.&lt;init&gt;(AppCompatDelegateImplV11.java:29)
                                                                                              at android.support.v7.app.AppCompatDelegateImplV14.&lt;init&gt;(AppCompatDelegateImplV14.java:54)
                                                                                              at android.support.v7.app.AppCompatDelegateImplV23.&lt;init&gt;(AppCompatDelegateImplV23.java:31)
                                                                                              at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:200)
                                                                                              at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
                                                                                              at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
                                                                                              at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
                                                                                              at com.electroniccode.ln.vodickrozzanimanja.banjaluka_activity.&lt;init&gt;(banjaluka_activity.java:46)
                                                                                              at java.lang.Class.newInstance(Native Method)
                                                                                              at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
                                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2329)
                                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
                                                                                              at android.app.ActivityThread.access$900(ActivityThread.java:157) 
                                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 
                                                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                              at android.os.Looper.loop(Looper.java:148) 
                                                                                              at android.app.ActivityThread.main(ActivityThread.java:5551) 
                                                                                              at java.lang.reflect.Method.invoke(Native Method) 
                                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
                                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)</code></p>
