title: Button Function not working - Android Studio
body: <p>Every time i run the code the application <strong>crashes</strong> it only works when i get rid of the button click events so as far as i know the problem is within the <em>Btnclklistner</em> event.</p>
  
  <pre><code>//package *******.*********;&lt;&lt;package not important 
  
  import android.app.Activity;
  import android.os.Bundle;
  //import android.view.Menu;&lt;&lt;i did this because i didnt really need to import them at the moment
  //import android.view.MenuItem;&lt;&lt;
  import android.view.View;
  import android.webkit.WebView;
  import android.widget.Button;
  
  public class MyActivity extends Activity {
  private WebView myWebview;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_my);
  
          myWebview = (WebView) findViewById(R.id.webView);
          myWebview.getSettings().setJavaScriptEnabled(true);
          myWebview.loadUrl("http://clarkstoninfoboard.com/");
          myWebview.getSettings().setLoadWithOverviewMode(true);
          myWebview.getSettings().setUseWideViewPort(true);
          myWebview.getSettings().setBuiltInZoomControls(true);
          myWebview.getSettings().setDisplayZoomControls(false);
         Btnclklistner();
  
          }
   private void Btnclklistner() {
          Button WebRefresh = (Button) findViewById(R.id.btn_reld);
          WebRefresh.setOnClickListener(new View.OnClickListener() {
  
           @Override
           public void onClick(View view) {
               myWebview.reload();
           }
          });
  
  
      }
  </code></pre>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>FATAL EXCEPTION: main
  Process: kirusoft.clarkstonupdates, PID: 7916 java.lang.RuntimeException: Unable to start activity ComponentInfo{kirusoft.clarkstonupdates/kirusoft.clarkstonupdates.MyActivity}: java.lang.NullPointerException
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2328)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
              at android.app.ActivityThread.access$900(ActivityThread.java:169)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:136)
              at android.app.ActivityThread.main(ActivityThread.java:5476)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.NullPointerException
              at kirusoft.clarkstonupdates.MyActivity.Btnclklistner(MyActivity.java:31)
              at kirusoft.clarkstonupdates.MyActivity.onCreate(MyActivity.java:26)
              at android.app.Activity.performCreate(Activity.java:5473)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
              at android.app.ActivityThread.access$900(ActivityThread.java:169)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:136)
              at android.app.ActivityThread.main(ActivityThread.java:5476)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p><strong>Layout XML</strong></p>
  
  <pre><code> &lt;Button
          style="?android:attr/borderlessButtonStyle"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Reload"
          android:textSize="10dp"
          android:textColor="#939393"
          android:id="@+id/btn_reld"
          android:layout_alignParentTop="true"
          android:layout_alignRight="@+id/webView"
          android:layout_alignEnd="@+id/webView"
          android:layout_above="@+id/webView" /&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/OPUj0.png" alt="enter image description here"></p>