title: How to set marginTop on LinearLayout with java for Android?
body: <p>I am trying to set the marginTop of a LinearLayout with java for my Android app. I keep on getting "force quits" all the time. This is my code:</p>
  
  <pre><code>    LinearLayout lay = (LinearLayout) findViewById(R.id.linearLayout1);
      LayoutParams lp = lay.getLayoutParams();
      lp.setMargins(10, 20, 30, 40);
      lay.setLayoutParams(lp);
  </code></pre>
  
  <p>What am I doing wrong ? </p>
  
  <p>This is what i get in my logcat: </p>
  
  <pre><code>01-12 18:50:16.237: D/AndroidRuntime(482): Shutting down VM
  01-12 18:50:16.237: W/dalvikvm(482): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
  01-12 18:50:16.237: E/AndroidRuntime(482): Uncaught handler: thread main exiting due to uncaught exception
  01-12 18:50:16.247: E/AndroidRuntime(482): java.lang.RuntimeException: Unable to start activity ComponentInfo{nu.katterevyn/nu.katterevyn.StartActivity}: java.lang.NullPointerException
  01-12 18:50:16.247: E/AndroidRuntime(482):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
  01-12 18:50:16.247: E/AndroidRuntime(482):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
  01-12 18:50:16.247: E/AndroidRuntime(482):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
  </code></pre>
  
  <p>Thank you!</p>