2012-07-09 202 views
0
TextView t=(TextView)findViewById(R.id.yourtextview); 
String text = "<fontcolor=#cc0029>Erste Farbe</font><font color=#ffcc00>zweiteFare</font>"; 
yourtextview.setText(Html.fromHtml(text)); 

获得NPE,我甚至增加了互联网许可。抛出空指针异常

+0

请接受的答案,如果你得到了想要的结果。 – AkashG 2012-07-09 06:25:14

+0

所有给出的答案是完美的,所以你需要接受答案。但我的问题是,为什么你的代码在编译时不会出错。而你的问题与互联网许可无关。 – 2012-07-09 06:36:03

回答

0

请更改下面的代码行

t.setText(Html.fromHtml(text)); 

,而不是

yourtextview.setText(Html.fromHtml(text)); 
1

您必须在textview中设置文本,而不是在textview的id中设置文本。

尝试做这个

t.setText(Html.fromHtml(text)); 
2

使用牛逼代替yourtextview

TextView t=(TextView)findViewById(R.id.yourtextview); 
String text = "<fontcolor=#cc0029>Erste Farbe</font><font color=#ffcc00>zweiteFare</font>"; 
t.setText(Html.fromHtml(text)); 
0

您需要调用TextView t而不是调用TextView ID。

使用此t.setText(Html.fromHtml(text)); 而不是使用 yourtextview.setText(Html.fromHtml(text));