I'm trying to open web browser when someone clicks on textview but as soon as i run the app i get the Null pointer exception error
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setMovementMethod(android.text.method.MovementMethod)' on a null object reference
In the xml file
<TextView
android:id="@+id/btnadfree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/txtfeedback1"
android:layout_margin="0dp"
android:background="@drawable/shopping"
android:gravity="center"
android:padding="10dp"
android:textColor="@android:color/white"
android:autoLink="web"
android:typeface="sans"/>
in the java file
txtadfree = (TextView) findViewById(R.id.btnadfree);
txtadfree.setMovementMethod(LinkMovementMethod.getInstance());
txtadfree.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("http://www.google.com"));
startActivity(browserIntent);
}
});