App is crashing when activity is loaded but if I uncomment the Make Register text as link to website, the code works, but the exact same copy of the code just different link will crash the app, code below.
The activity is for a login page with links to register and to reset password
LogCat
08-04 21:34:07.006 11888-11888/net.twistedcircuits.greenroadsmalta
D/LOGIN PAGE: ______login page loaded
08-04 21:34:07.006 11888-11888/net.twistedcircuits.greenroadsmalta D/AndroidRuntime: Shutting down VM
08-04 21:34:07.007 11888-11888/net.twistedcircuits.greenroadsmalta E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.twistedcircuits.greenroadsmalta, PID: 11888
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.twistedcircuits.greenroadsmalta/net.twistedcircuits.greenroadsmalta.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setMovementMethod(android.text.method.MovementMethod)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2924)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setMovementMethod(android.text.method.MovementMethod)' on a null object reference
at net.twistedcircuits.greenroadsmalta.LoginActivity.onCreate(LoginActivity.java:56)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//lock screen for always Portrait mode
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Log.d("LOGIN PAGE","______login page loaded");
loginEmail = (EditText) (findViewById(R.id.LoginEmail_editText));
loginPassword = (EditText) (findViewById(R.id.LoginPassword_editText));
//************************ Make Register text as link to website ************************//
/*
registerLinkText = (TextView) (findViewById(R.id.registerLink_textView));
registerLinkText.setClickable(true);
registerLinkText.setMovementMethod(LinkMovementMethod.getInstance());
register_text = "<a href='http://www.google.com'>No account yet? Create One</a>";
registerLinkText.setText(fromHtml(register_text));
registerLinkText.setLinkTextColor(getResources().getColor(R.color.loginTextColor));
*/
//**********************************************************************************//
//************************ Make Lost Password text as link to website ************************//
lostPasswordLinkText = (TextView) (findViewById(R.id.lostPasswordLink_textView));
lostPasswordLinkText.setClickable(true);
registerLinkText.setMovementMethod(LinkMovementMethod.getInstance());
password_text = "<a href='https://www.google.com.mt/search?q=dementia&spell=1&sa=X&ved=0ahUKEwiWyovunL7VAhXDzRQKHa2ND_0QBQgkKAA&biw=1152&bih=956'>Forgot your password?</a>";
lostPasswordLinkText.setText(fromHtml(password_text));
lostPasswordLinkText.setLinkTextColor(getResources().getColor(R.color.loginTextColor));
}
}