title: Android OnClickListner Start intent error
body: <pre><code>import com.nextgenintl.edlineformobile.R;
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.view.View;
  import android.view.Window;
  import android.webkit.WebChromeClient;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.Button;
  import android.widget.ProgressBar;
  
  @SuppressLint("SetJavaScriptEnabled")
  public class MainActivity extends Activity {
      /** Called when the activity is first created. */
      private WebView myWebView;
      private ProgressBar progressBar1;
      private Button button1;
       final Activity activity = this;
  
       @Override
       public void onBackPressed() {
           if (myWebView.copyBackForwardList().getCurrentIndex() &gt; 0) {
               myWebView.goBack();
           }
           else {
               super.onBackPressed(); // finishes activity
           }
       }
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          getWindow().requestFeature(Window.FEATURE_PROGRESS);
          setContentView(R.layout.activity_main);
  
  
          myWebView = (WebView) findViewById(R.id.webView1); 
          progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
          button1 = (Button) findViewById(R.id.button1);
  
  
  
          // 
  
          String url = "http://www.example.com"; 
          myWebView.setWebViewClient(new WebViewClient());
          myWebView.getSettings().setJavaScriptEnabled(true);
          myWebView.loadUrl(url);
  
  
          button1.setOnClickListener( new View.OnClickListener() {
              public void onClick(View v) {
              String currentUrl = myWebView.getUrl();
              Intent i = new Intent(Intent.ACTION_VIEW);
              i.setData(Uri.parse(currentUrl));
              startActivity(i);
              }
          });
  
          myWebView.setWebChromeClient(new WebChromeClient() 
          {  
  
                 public void onProgressChanged(WebView view, int progress) 
                 {  
                     if (progress&lt;100)
                     {
                         progressBar1.setVisibility(ProgressBar.VISIBLE);
                     }
                     else if (progress==100)
                     {
                         progressBar1.setVisibility(ProgressBar.GONE);
                     }
                     progressBar1.setProgress(progress);  
                 }   
          });
      }
  }
  </code></pre>
  
  <p>I have this code, and on a button click, it is supposed to send the current url to a browser. However, the app crashes. What should I fix and how to properly use onckicklistner? I have seen many questions that did not solve my problem. Thank you.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My log cat:</p>
  
  <pre><code>02-03 12:29:55.385: E/cutils-trace(1278): Error opening trace file: No such file or directory (2)
  02-03 12:29:55.405: D/TilesManager(1278): Starting TG #0, 0xb8abf2e8
  02-03 12:29:55.409: D/TilesManager(1278): new EGLContext from framework: b8a1fe00 
  02-03 12:29:55.409: D/GLWebViewState(1278): Reinit shader
  02-03 12:29:55.717: D/GLWebViewState(1278): Reinit transferQueue
  02-03 12:29:57.133: A/libc(1278): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1299 (WebViewCoreThre)
  02-03 12:30:01.613: D/dalvikvm(1324): Late-enabling CheckJNI
  02-03 12:30:01.693: D/dalvikvm(1324): GC_FOR_ALLOC freed 168K, 25% free 2777K/3656K, paused 6ms, total 6ms
  02-03 12:30:01.701: D/dalvikvm(1324): GC_FOR_ALLOC freed 0K, 24% free 2929K/3808K, paused 6ms, total 6ms
  02-03 12:30:01.705: I/dalvikvm-heap(1324): Grow heap (frag case) to 3.878MB for 349068-byte allocation
  02-03 12:30:01.709: D/dalvikvm(1324): GC_FOR_ALLOC freed 3K, 22% free 3267K/4152K, paused 2ms, total 2ms
  02-03 12:30:01.717: D/dalvikvm(1324): GC_FOR_ALLOC freed 152K, 25% free 3267K/4304K, paused 3ms, total 3ms
  02-03 12:30:01.721: I/dalvikvm-heap(1324): Grow heap (frag case) to 4.208MB for 349068-byte allocation
  02-03 12:30:01.729: D/dalvikvm(1324): GC_FOR_ALLOC freed &lt;1K, 23% free 3608K/4648K, paused 9ms, total 9ms
  02-03 12:30:01.749: D/dalvikvm(1324): GC_FOR_ALLOC freed 151K, 23% free 3608K/4648K, paused 5ms, total 5ms
  02-03 12:30:01.757: I/dalvikvm-heap(1324): Grow heap (frag case) to 4.542MB for 349068-byte allocation
  02-03 12:30:01.765: D/dalvikvm(1324): GC_FOR_ALLOC freed &lt;1K, 21% free 3949K/4992K, paused 3ms, total 3ms
  02-03 12:30:01.765: D/dalvikvm(1324): GC_FOR_ALLOC freed 151K, 21% free 3950K/4992K, paused 2ms, total 2ms
  02-03 12:30:01.765: I/dalvikvm-heap(1324): Grow heap (frag case) to 4.875MB for 349068-byte allocation
  02-03 12:30:01.769: D/dalvikvm(1324): GC_FOR_ALLOC freed &lt;1K, 20% free 4290K/5336K, paused 2ms, total 2ms
  02-03 12:30:01.773: D/dalvikvm(1324): GC_FOR_ALLOC freed 151K, 20% free 4291K/5336K, paused 2ms, total 2ms
  02-03 12:30:01.777: I/dalvikvm-heap(1324): Grow heap (frag case) to 5.208MB for 349068-byte allocation
  02-03 12:30:01.777: D/dalvikvm(1324): GC_FOR_ALLOC freed 0K, 19% free 4632K/5680K, paused 2ms, total 2ms
  02-03 12:30:01.785: D/dalvikvm(1324): GC_FOR_ALLOC freed 303K, 20% free 4822K/6024K, paused 3ms, total 3ms
  02-03 12:30:01.789: D/dalvikvm(1324): GC_FOR_ALLOC freed &lt;1K, 18% free 4974K/6024K, paused 3ms, total 3ms
  02-03 12:30:01.797: D/dalvikvm(1324): GC_FOR_ALLOC freed 151K, 17% free 5315K/6368K, paused 3ms, total 3ms
  02-03 12:30:01.813: D/dalvikvm(1324): GC_FOR_ALLOC freed 256K, 18% free 5738K/6936K, paused 2ms, total 2ms
  02-03 12:30:01.813: I/dalvikvm-heap(1324): Grow heap (frag case) to 7.364MB for 1127532-byte allocation
  02-03 12:30:01.817: D/dalvikvm(1324): GC_FOR_ALLOC freed 1K, 15% free 6838K/8040K, paused 3ms, total 3ms
  02-03 12:30:01.821: D/dalvikvm(1324): GC_FOR_ALLOC freed &lt;1K, 15% free 6837K/8040K, paused 3ms, total 3ms
  02-03 12:30:01.829: I/dalvikvm-heap(1324): Grow heap (frag case) to 9.782MB for 2536932-byte allocation
  02-03 12:30:01.833: D/dalvikvm(1324): GC_FOR_ALLOC freed &lt;1K, 12% free 9314K/10520K, paused 5ms, total 5ms
  02-03 12:30:01.937: D/dalvikvm(1324): GC_FOR_ALLOC freed 1585K, 21% free 9437K/11856K, paused 6ms, total 6ms
  02-03 12:30:01.953: D/dalvikvm(1324): GC_FOR_ALLOC freed 456K, 12% free 10460K/11856K, paused 3ms, total 3ms
  02-03 12:30:02.081: D/libEGL(1324): loaded /system/lib/egl/libEGL_genymotion.so
  02-03 12:30:02.081: D/(1324): HostConnection::get() New Host Connection established 0xb8a4e328, tid 1324
  02-03 12:30:02.093: D/libEGL(1324): loaded /system/lib/egl/libGLESv1_CM_genymotion.so
  02-03 12:30:02.097: D/libEGL(1324): loaded /system/lib/egl/libGLESv2_genymotion.so
  02-03 12:30:02.157: W/EGL_genymotion(1324): eglSurfaceAttrib not implemented
  02-03 12:30:02.161: E/OpenGLRenderer(1324): Getting MAX_TEXTURE_SIZE from GradienCache
  02-03 12:30:02.169: E/OpenGLRenderer(1324): Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
  02-03 12:30:02.173: D/OpenGLRenderer(1324): Enabling debug mode 0
  02-03 12:30:04.161: W/chromium_net(1324): external/chromium/net/disk_cache/backend_impl.cc:1835: [0203/123004:WARNING:backend_impl.cc(1835)] Destroying invalid entry.
  02-03 12:30:04.873: E/cutils-trace(1324): Error opening trace file: No such file or directory (2)
  02-03 12:30:04.889: D/TilesManager(1324): Starting TG #0, 0xb8bb4350
  02-03 12:30:04.889: D/TilesManager(1324): new EGLContext from framework: b8a50898 
  02-03 12:30:04.889: D/GLWebViewState(1324): Reinit shader
  02-03 12:30:05.417: D/GLWebViewState(1324): Reinit transferQueue
  02-03 12:45:45.121: D/dalvikvm(2158): GC_FOR_ALLOC freed 172K, 25% free 2777K/3660K, paused 4ms, total 4ms
  02-03 12:45:45.125: D/dalvikvm(2158): GC_FOR_ALLOC freed 3K, 24% free 2925K/3812K, paused 3ms, total 3ms
  02-03 12:45:45.125: I/dalvikvm-heap(2158): Grow heap (frag case) to 3.875MB for 349068-byte allocation
  02-03 12:45:45.129: D/dalvikvm(2158): GC_FOR_ALLOC freed &lt;1K, 22% free 3266K/4156K, paused 3ms, total 3ms
  02-03 12:45:45.141: D/dalvikvm(2158): GC_FOR_ALLOC freed 151K, 25% free 3267K/4308K, paused 4ms, total 4ms
  02-03 12:45:45.141: I/dalvikvm-heap(2158): Grow heap (frag case) to 4.208MB for 349068-byte allocation
  02-03 12:45:45.149: D/dalvikvm(2158): GC_FOR_ALLOC freed &lt;1K, 23% free 3608K/4652K, paused 2ms, total 4ms
  02-03 12:45:45.153: D/dalvikvm(2158): GC_FOR_ALLOC freed 151K, 23% free 3608K/4652K, paused 1ms, total 1ms
  02-03 12:45:45.153: I/dalvikvm-heap(2158): Grow heap (frag case) to 4.541MB for 349068-byte allocation
  02-03 12:45:45.165: D/dalvikvm(2158): GC_FOR_ALLOC freed &lt;1K, 21% free 3949K/4996K, paused 4ms, total 4ms
  02-03 12:45:45.173: D/dalvikvm(2158): GC_FOR_ALLOC freed 151K, 21% free 3949K/4996K, paused 5ms, total 5ms
  02-03 12:45:45.173: I/dalvikvm-heap(2158): Grow heap (frag case) to 4.875MB for 349068-byte allocation
  02-03 12:45:45.193: D/dalvikvm(2158): GC_FOR_ALLOC freed &lt;1K, 20% free 4290K/5340K, paused 2ms, total 2ms
  02-03 12:45:45.217: D/dalvikvm(2158): GC_FOR_ALLOC freed 151K, 20% free 4291K/5340K, paused 18ms, total 21ms
  02-03 12:45:45.221: I/dalvikvm-heap(2158): Grow heap (frag case) to 5.208MB for 349068-byte allocation
  02-03 12:45:45.237: D/dalvikvm(2158): GC_FOR_ALLOC freed &lt;1K, 19% free 4632K/5684K, paused 1ms, total 1ms
  02-03 12:45:45.249: D/dalvikvm(2158): GC_FOR_ALLOC freed 303K, 20% free 4822K/6028K, paused 3ms, total 3ms
  02-03 12:45:45.253: D/dalvikvm(2158): GC_FOR_ALLOC freed &lt;1K, 18% free 4973K/6028K, paused 3ms, total 3ms
  02-03 12:45:45.265: D/dalvikvm(2158): GC_FOR_ALLOC freed 151K, 17% free 5315K/6372K, paused 5ms, total 6ms
  02-03 12:45:45.273: D/dalvikvm(2158): GC_FOR_ALLOC freed 256K, 18% free 5738K/6940K, paused 2ms, total 2ms
  02-03 12:45:45.277: I/dalvikvm-heap(2158): Grow heap (frag case) to 7.364MB for 1127532-byte allocation
  02-03 12:45:45.281: D/dalvikvm(2158): GC_FOR_ALLOC freed 1K, 15% free 6837K/8044K, paused 4ms, total 4ms
  02-03 12:45:45.285: D/dalvikvm(2158): GC_FOR_ALLOC freed &lt;1K, 16% free 6837K/8044K, paused 4ms, total 4ms
  02-03 12:45:45.289: I/dalvikvm-heap(2158): Grow heap (frag case) to 9.782MB for 2536932-byte allocation
  02-03 12:45:45.293: D/dalvikvm(2158): GC_FOR_ALLOC freed &lt;1K, 12% free 9314K/10524K, paused 5ms, total 5ms
  02-03 12:45:45.373: D/dalvikvm(2158): GC_FOR_ALLOC freed 1585K, 21% free 9437K/11860K, paused 2ms, total 2ms
  02-03 12:45:45.385: D/dalvikvm(2158): GC_FOR_ALLOC freed 456K, 12% free 10460K/11860K, paused 4ms, total 5ms
  02-03 12:45:45.393: D/AndroidRuntime(2158): Shutting down VM
  02-03 12:45:45.393: W/dalvikvm(2158): threadid=1: thread exiting with uncaught exception (group=0xa4c0f648)
  02-03 12:45:45.409: E/AndroidRuntime(2158): FATAL EXCEPTION: main
  02-03 12:45:45.409: E/AndroidRuntime(2158): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nextgenintl.edlineformobile/com.nextgenintl.edlineformobile.MainActivity}: java.lang.NullPointerException
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.os.Handler.dispatchMessage(Handler.java:99)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.os.Looper.loop(Looper.java:137)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.app.ActivityThread.main(ActivityThread.java:5103)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at java.lang.reflect.Method.invokeNative(Native Method)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at java.lang.reflect.Method.invoke(Method.java:525)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at dalvik.system.NativeStart.main(Native Method)
  02-03 12:45:45.409: E/AndroidRuntime(2158): Caused by: java.lang.NullPointerException
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at com.nextgenintl.edlineformobile.MainActivity.onCreate(MainActivity.java:58)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.app.Activity.performCreate(Activity.java:5133)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
  02-03 12:45:45.409: E/AndroidRuntime(2158):     ... 11 more
  02-03 12:45:48.285: D/dalvikvm(2185): GC_FOR_ALLOC freed 175K, 25% free 2777K/3664K, paused 4ms, total 4ms
  02-03 12:45:48.289: D/dalvikvm(2185): GC_FOR_ALLOC freed 0K, 24% free 2929K/3816K, paused 4ms, total 4ms
  02-03 12:45:48.293: I/dalvikvm-heap(2185): Grow heap (frag case) to 3.878MB for 349068-byte allocation
  02-03 12:45:48.305: D/dalvikvm(2185): GC_FOR_ALLOC freed 3K, 22% free 3266K/4160K, paused 10ms, total 10ms
  02-03 12:45:48.317: D/dalvikvm(2185): GC_FOR_ALLOC freed 152K, 25% free 3267K/4312K, paused 3ms, total 3ms
  02-03 12:45:48.321: I/dalvikvm-heap(2185): Grow heap (frag case) to 4.208MB for 349068-byte allocation
  02-03 12:45:48.341: D/dalvikvm(2185): GC_FOR_ALLOC freed &lt;1K, 23% free 3608K/4656K, paused 21ms, total 21ms
  02-03 12:45:48.353: D/dalvikvm(2185): GC_FOR_ALLOC freed 151K, 23% free 3608K/4656K, paused 4ms, total 4ms
  02-03 12:45:48.353: I/dalvikvm-heap(2185): Grow heap (frag case) to 4.541MB for 349068-byte allocation
  02-03 12:45:48.357: D/dalvikvm(2185): GC_FOR_ALLOC freed &lt;1K, 22% free 3949K/5000K, paused 2ms, total 2ms
  02-03 12:45:48.365: D/dalvikvm(2185): GC_FOR_ALLOC freed 151K, 22% free 3949K/5000K, paused 3ms, total 3ms
  02-03 12:45:48.365: I/dalvikvm-heap(2185): Grow heap (frag case) to 4.875MB for 349068-byte allocation
  02-03 12:45:48.369: D/dalvikvm(2185): GC_FOR_ALLOC freed &lt;1K, 20% free 4290K/5344K, paused 4ms, total 4ms
  02-03 12:45:48.373: D/dalvikvm(2185): GC_FOR_ALLOC freed 151K, 20% free 4291K/5344K, paused 2ms, total 2ms
  02-03 12:45:48.373: I/dalvikvm-heap(2185): Grow heap (frag case) to 5.208MB for 349068-byte allocation
  02-03 12:45:48.381: D/dalvikvm(2185): GC_FOR_ALLOC freed &lt;1K, 19% free 4632K/5688K, paused 3ms, total 4ms
  02-03 12:45:48.393: D/dalvikvm(2185): GC_FOR_ALLOC freed 303K, 21% free 4822K/6032K, paused 2ms, total 2ms
  02-03 12:45:48.397: D/dalvikvm(2185): GC_FOR_ALLOC freed &lt;1K, 18% free 4973K/6032K, paused 2ms, total 2ms
  02-03 12:45:48.405: D/dalvikvm(2185): GC_FOR_ALLOC freed 151K, 17% free 5315K/6376K, paused 3ms, total 3ms
  02-03 12:45:48.417: D/dalvikvm(2185): GC_FOR_ALLOC freed 256K, 18% free 5738K/6944K, paused 2ms, total 2ms
  02-03 12:45:48.417: I/dalvikvm-heap(2185): Grow heap (frag case) to 7.364MB for 1127532-byte allocation
  02-03 12:45:48.421: D/dalvikvm(2185): GC_FOR_ALLOC freed 1K, 16% free 6837K/8048K, paused 3ms, total 3ms
  02-03 12:45:48.425: D/dalvikvm(2185): GC_FOR_ALLOC freed &lt;1K, 16% free 6837K/8048K, paused 3ms, total 3ms
  02-03 12:45:48.429: I/dalvikvm-heap(2185): Grow heap (frag case) to 9.782MB for 2536932-byte allocation
  02-03 12:45:48.433: D/dalvikvm(2185): GC_FOR_ALLOC freed &lt;1K, 12% free 9314K/10528K, paused 3ms, total 3ms
  02-03 12:45:48.505: D/dalvikvm(2185): GC_FOR_ALLOC freed 1585K, 21% free 9437K/11864K, paused 2ms, total 2ms
  02-03 12:45:48.521: D/dalvikvm(2185): GC_FOR_ALLOC freed 456K, 12% free 10460K/11864K, paused 6ms, total 6ms
  02-03 12:45:48.529: D/AndroidRuntime(2185): Shutting down VM
  02-03 12:45:48.529: W/dalvikvm(2185): threadid=1: thread exiting with uncaught exception (group=0xa4c0f648)
  02-03 12:45:48.529: E/AndroidRuntime(2185): FATAL EXCEPTION: main
  02-03 12:45:48.529: E/AndroidRuntime(2185): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nextgenintl.edlineformobile/com.nextgenintl.edlineformobile.MainActivity}: java.lang.NullPointerException
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.os.Handler.dispatchMessage(Handler.java:99)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.os.Looper.loop(Looper.java:137)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.app.ActivityThread.main(ActivityThread.java:5103)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at java.lang.reflect.Method.invokeNative(Native Method)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at java.lang.reflect.Method.invoke(Method.java:525)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at dalvik.system.NativeStart.main(Native Method)
  02-03 12:45:48.529: E/AndroidRuntime(2185): Caused by: java.lang.NullPointerException
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at com.nextgenintl.edlineformobile.MainActivity.onCreate(MainActivity.java:58)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.app.Activity.performCreate(Activity.java:5133)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
  02-03 12:45:48.529: E/AndroidRuntime(2185):     ... 11 more
  </code></pre>