I have an activity with multiple tabs and each tab consists of a fragment with some text inside. I would like to have a text with "Read More" which is a link to an URL. Without having the link, everything works fine, but when I try to implement it, I get
E/UncaughtException: java.lang.NullPointerException
So I assume it is the way I implement it. Right now, the fragment has this:
public class About_us extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_about_us, container, false);
//The part below is For Read More
TextView t2 = (TextView) getView().findViewById(R.id.read_more);
if (t2 != null) {
t2.setMovementMethod(LinkMovementMethod.getInstance());
}
return rootView;
}
}
"read_more" layout has this for the TextView:
< TextView
android: id = "@+id/read_more"
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: clickable = "true"
android: text = "@string/link_to_the_website"
android: textColor = "@color/buttonColorPressed" / >
And link_to_website is given in the strings:
< string name = "link_to_the_website" > < a href = "www.google.com/" > Read More Here < /a></string >
Can anyone help me to figure out what is it that I wrote wrong?