Question: I have a TextView in my app and I want to change its textSize programmatically using the setTextSize method, but everytime I ran my code, I got an error message : "java.lang.NullPointerException". I tried to print the value of the TextView and it got NULL value. 

Here's my code:

LoadActivity.java

```
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class LoadActivity extends Activity{

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView text = (TextView) findViewById(R.id.loadTextView);
        try{
            System.out.println("TextView: "+text);
        }catch(Exception e){
            System.err.println(e);
        }
        text.setTextSize(30);
        setContentView(R.layout.activity_load);
    }
}

```

activity\_load.xml

```
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffffff">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Please Wait"
        android:id="@+id/loadTextView"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:typeface="monospace"
        android:textSize="35sp"
        android:textStyle="bold"
        android:textColor="#000000"/>
</RelativeLayout>

```

What do you think is the problem?

Answer: 
`setContentView(R.layout.activity_load);` should be declared before initializing your views(TextView) and `System.out.println("TextView: "+text);` is not correct form to print value. The correct form is `System.out.println("TextView: "+text.getText().toString());`

So your corrected code will be like this

```
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class LoadActivity extends Activity{

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_load);
TextView text = (TextView) findViewById(R.id.loadTextView);
    try{
        System.out.println("TextView: "+text.getText().toString());
    }catch(Exception e){
        System.err.println(e);
    }
 text.setTextSize(30);
}
}

```
Use this in your onCreate Method

```
    setContentView(R.layout.activity_load);
    TextView text = (TextView) findViewById(R.id.loadTextView);
    text.setTextSize(30);

```