I have to change theTypeface
of EditText
dynamically and also process the hint text if the Typeface changed. I simply do as following:
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_textBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/textBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_date" />
</android.support.design.widget.TextInputLayout>
And my code snippet is as follow:
EditText textBox = (EditText) findViewById(R.id.textBox);
Typeface tf = Typeface.createFromAsset(this, "myfont.ttf");
textBox.setTypeface(tf);
String hintText = textBox.getHint().toString(); //Got NullPointerException here....
String newText = processText(hintText); //This will process the hint text;
textBox.setHint(newText);
When I runt the program, I got the following exception:
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
Please help me to solve this problem.