title: Convert dip to px in Android
body: <p>I had written method to get the pixels from dip but it is not working. It give me runtime error.</p>
  <p>Actually I was running this method in separate class and initialized in my Activity class</p>
  <pre><code>Board board = new Board(this);
  board.execute(URL);
  </code></pre>
  <p>This code runs asynchronously. Please help me.</p>
  <pre><code>public float getpixels(int dp){
      //Resources r = boardContext.getResources();
      //float px = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpis, r.getDisplayMetrics());
          
      final float scale = this.boardContext.getResources().getDisplayMetrics().density;
      int px = (int) (dp * scale + 0.5f);
  
      return px;
  }
  </code></pre>