title: TestNG- pass parameters to the constructor where parameters are decided based on the testname
body: <p>I'm new to TestNG, here is my question..
  I need to pass data to my @test methods via constructor, I've written the below code but getting a null pointer exception,</p>
  
  <pre><code>public class ParameterTests {
  String x=null;
  int y;
  
  //no-arg constructor
  public ParameterTests(){
  
  }
  
  @Factory(dataProvider="MyData")
  public ParameterTests(String x, int y ){
      this.x=x;
      this.y=y;
  }
  
  @DataProvider(name = "MyData")
  public Object[][] DataSupplier(Method meth) {
  
      Object[][] result = null;
  
      if (meth.getName().equals("Test1")) {
          result = new Object[][] {
              {"Test1-D1", 1 }, {"Test1-D2", 2 } 
          };
  
      } else if (meth.getName().equals("Test2")) {
          result = new Object[][] { 
              { "Test2-D3", 3 }, 
              { "Test2-D4", 4 } 
          };
      }
  
      return result;  
  
  }
  
  
  @Test//(dataProvider = "MyData")
  public void Test1() {
   System.out.println(x + " " + y);
  } 
  
  @Test//(dataProvider = "MyData")
  public void Test2() {
   System.out.println(x + " " + y);
  } 
  
  }
  </code></pre>
  
  <p>AND I am getting 
  java.lang.RuntimeException: java.lang.NullPointerException
      at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:161)</p>