Getting error while Accessing variable to another class

Hi , i entered phone number using sendkeys for signup, now i want to access that phone number again for login but i got null pointer exception error.

can anyone tell me how do this

I created a class name UsernameValidationTest.java where there is a implementation for method "enterPhoneNO(); , I accessed that method for my test case (“signupThenLogin”).
public class SignupThenLoginWithSameNumberTest extends InvokeApp{
@Test(priority=1)

public void signup() throws Exception

{

  UsernameValidationTest userprofile=new UsernameValidationTest();

userprofile.enterPhoneNo();         

}

@Test(priority=2)

public void login() throws Exception

{

 UsernameValidationTest userprofile=new UsernameValidationTest();

 userprofile.enterPhoneNo();

         }      

}

UsernameValidationTest.java

public class UsernameValidationTest extends InvokeApp {

String phoneRemainingNumbers, phoneNo=“3”;

int phoneLimit=9,randomNumber;

@Test (priority=1)

 public void generateRandomPhoneNo()

 {

openApp(“MobileApp”);

//Generate random phone number

for(int i=0;i<=phoneLimit;i++){

Random r=new Random();

randomNumber=r.nextInt(10);

phoneRemainingNumbers=String.valueOf(randomNumber);

phoneRemainingNumbers=String.valueOf(randomNumber);

phoneNo=phoneNo.concat(phoneRemainingNumbers); }

}

@Test (priority=2)

public void enterPhoneNo(){

enterPhoneNo = new VerifyViaOTP(driver);

enterPhoneNo.mobileNumber.sendKeys(phoneNo);

enterPhoneNo.sendOTP.click();

}

}

the code is working fine for UsernameValidationTest.java but for my test “SignupthenLogin” app enter number for signup it works fine but when app open again for login, it shows error “NullPointerException”

@ZaidanJawaid @Aleksei or anyone can help?

I want to get existing value of the phone number.

no clear where this variable declared… inside InvokeApp class?

this is your code formatted:

public class testClass {


    public class SignupThenLoginWithSameNumberTest extends InvokeApp {
        @Test(priority = 1)
        public void signup() {
            UsernameValidationTest userprofile = new UsernameValidationTest();
            userprofile.enterPhoneNo();
        }

        @Test(priority = 2)
        public void login() {
            UsernameValidationTest userprofile = new UsernameValidationTest();
            userprofile.enterPhoneNo();
        }
    }

    public class UsernameValidationTest extends InvokeApp {
        String phoneRemainingNumbers, phoneNo = "3";
        int phoneLimit = 9, randomNumber;

        @Test(priority = 1)
        public void generateRandomPhoneNo() {
            openApp("MobileApp");

            // Generate random phone number
            for (int i = 0; i <= phoneLimit; i++) {
                Random r = new Random();
                randomNumber = r.nextInt(10);
                phoneRemainingNumbers = String.valueOf(randomNumber);
                phoneRemainingNumbers = String.valueOf(randomNumber);
                phoneNo = phoneNo.concat(phoneRemainingNumbers);
            }
        }

        @Test(priority = 2)
        public void enterPhoneNo() {

            enterPhoneNo = new VerifyViaOTP(driver);
            enterPhoneNo.mobileNumber.sendKeys(phoneNo);

            enterPhoneNo.sendOTP.click();

        }
    }
}