I know this is a commonly asked question but I can not find the solution for this plus the fact that I'm a beginner in programming.
I'm trying to make text wrap around image
work but I get null point exception
error
Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
when passing TextView id to MainActiviy
So I have this Fragment.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="make.appaplication.Fragment4">
<!-- TODO: Update blank fragment layout -->
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/nature"
android:id="@+id/imageView"
android:layout_weight="1"
android:layout_marginRight="17dp"
android:layout_marginEnd="17dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/textView3"
android:textSize="17dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/text_page_1"
android:layout_below="@+id/textView5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
and passing its values to MainActivity like so
String text = getString(R.string.text_page_1);
Drawable dIcon = ContextCompat.getDrawable(getApplicationContext(),R.drawable.nature);
int leftMargin = dIcon.getIntrinsicWidth() + 10;
SpannableString ss = new SpannableString(text);
ss.setSpan(new MyLeadingMarginSpan2(3, leftMargin), 0, ss.length(), 0);
TextView messageView = (TextView) findViewById(R.id.textView3);
messageView.setText(ss);
And I have these two lines of code
TextView messageView = (TextView) findViewById(R.id.textView3);
messageView.setText(ss);
after
setContentView(R.layout.activity_main);
and in onCreate method
Can anybody help me to solve this problem, please?