title: How to get screen width in fragment?
body: <p>so im using the following code to get my screen width in a fragment, but my app keeps crashing due to some null point exception, and i can't figure it out.</p>
  
  <p>Here's the code im using.</p>
  
  <pre><code>            DisplayMetrics displayMetrics = new DisplayMetrics();
              getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
              int height = displayMetrics.heightPixels;
              int width = displayMetrics.widthPixels;
  </code></pre>
  
  <p>It says im crashing on this line : <code>getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);</code></p>
  
  <p>No idea what is going on hope someone can help!</p>
  
  <p>Here is my stack trace:</p>
  
  <pre><code> FATAL EXCEPTION: main
                                                                                 Process: com.daprlabs.aaron.swipedeck2, PID: 25417
                                                                                 java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.WindowManager android.support.v4.app.FragmentActivity.getWindowManager()' on a null object reference
                                                                                     at com.daprlabs.aaron.zivitApp.Main.FragmentDiscover$SwipeDeckAdapter.getView(FragmentDiscover.java:398)
                                                                                     at com.daprlabs.aaron.swipedeck.SwipeDeck.addNextView(SwipeDeck.java:215)
                                                                                     at com.daprlabs.aaron.swipedeck.SwipeDeck.onLayout(SwipeDeck.java:208)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                                     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                                     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                                     at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1799)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                                     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                                     at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1193)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                                     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                                     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                                     at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                                     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                                     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                                     at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                                     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                                     at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2720)
                                                                                     at android.view.View.layout(View.java:16668)
                                                                                     at android.view.ViewGroup.layout(ViewGroup.java:5439)
                                                                                     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2202)
                                                                                     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1955)
                                                                                     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1125)
                                                                                     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6100)
                                                                                     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                                     at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                                                                                     at android.view.Choreographer.doFrame(Choreographer.java:606)
                                                                                     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                                                                                     at android.os.Handler.handleCallback(Handler.java:739)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                  at android.os.
  05-03 15:47:52.762 1218-4087/? W/ActivityManager:   Force finishing activity com.daprlabs.aaron.swipedeck2/com.daprlabs.aaron.zivitApp.Main.Main
  </code></pre>