<分区>
我必须动态更改EditText
的Typeface
,并且如果Typeface 更改了,还要处理提示文本。我只是做如下:
<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>
我的代码 fragment 如下:
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);
运行程序时,出现以下异常:
java.lang.NullPointerException:尝试在空对象引用上调用接口(interface)方法“java.lang.String java.lang.CharSequence.toString()”
请帮我解决这个问题。