我没有从创建新类中获得外部字体,我在其中定义了外部字体。
字体样式.Java
public class FontStyle extends Activity{
public final static String roboto_regular = "fonts/roboto_regular.ttf";
public Typeface font_roboto_regular = Typeface.createFromAsset(getAssets(),
roboto_regular);
}
和MainActivity.Java
public class MainActivity extends Activity {
FontStyle font_style;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fontStyling();
}
private void fontStyling() {
TextView test= (TextView) findViewById(R.id.tv_test);
test.setTypeface(font_style.font_roboto_regular );
}
我收到此错误或 logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.MainActivity}: java.lang.NullPointerException
请人纠正我:提前谢谢。