Getting the error java.lang.NullPointerException

i used the following code to input a string

string a = null;

if( sa.hasNext()) {
a=sa.nextLine();
}

int len=a.length();

the error(java.lang.NullPointerException) is pointing to the last line above.

@jayyp35,
for input use:
a = sa.next();

Avoid using hasNext(). If the error persists, please share your complete code

It’s working. Thanks!