title: How To Get The Current View - Android
body: <p>I am getting NULL pointer exception currently, when I run this thread</p>
  
  <pre><code>public void run() {
      long idle = 0;
      this.touch();
      do {
          idle = System.currentTimeMillis() - lastUsed;
          Log.d(TAG, "Application is idle for " + idle + " ms");
          if ((idle &gt; 5000) &amp;&amp; (check == false)) { // Checking For 2 Minutes.
              Log.e("AthanAd", "2 minutes over - Show Ad.");
              adView = (AdView) view.findViewById(R.id.adView);
              adView.loadAd(new AdRequest());
              check = true;
          }
          try {
              Thread.sleep(8000); // check every 5 seconds
          } catch (InterruptedException e) {
              Log.d(TAG, "Waiter interrupted!");
          }
          if (idle &gt; period) {
              idle = 0;
              // do something here - e.g. call popup or so
          }
      } while (!stop);
      Log.d(TAG, "Finishing Waiter thread");
  }
  </code></pre>
  
  <p>I am getting the exception this line.</p>
  
  <p><strong><code>adView = (AdView) view.findViewById(R.id.adView);</code></strong></p>
  
  <p>At the top of the application I have declared <strong>View view;</strong> but I know I have not linked it to any view.</p>
  
  <p>My question is: <strong>How I can get the view visible to screen?</strong></p>