Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 字体-碎片使我的应用程序在设备上崩溃_Android_Android Fragments - Fatal编程技术网

Android 字体-碎片使我的应用程序在设备上崩溃

Android 字体-碎片使我的应用程序在设备上崩溃,android,android-fragments,Android,Android Fragments,我正试图在Fragment中为TextView使用自定义字体,但我的应用程序在手机(4.4.2)上崩溃,不过Android Studio中没有显示任何错误 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Typeface font = Typeface.createFromAsset(getActivity().getAssets(),

我正试图在Fragment中为TextView使用自定义字体,但我的应用程序在手机(4.4.2)上崩溃,不过Android Studio中没有显示任何错误

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/androidnation_b.ttf");
    TextView txt = (TextView) getActivity().findViewById(R.id.textView1);
    txt.setTypeface(font);

    return inflater.inflate(R.layout.activity_fragment, container, false);
}
当我在返回充气器应用程序工作之前评论这三行时。 我正在寻找一个解决方案几乎一个星期,但没有任何帮助

下面是我的ttf路径:Project->src/main/assets/font/androidnation\u b.ttf

我在fragment_布局视图中具有该id(textView1)
任何解决这一问题的方法都很好。

这是一个解决方案,你喜欢吗

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View v=inflater.inflate(R.layout.activity_fragment, container, false);

Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/androidnation_b.ttf");

TextView txt = (TextView) v.findViewById(R.id.textView1);
txt.setTypeface(font);

return v;
}
试着这样做:

View view = inflater.inflate(R.layout.activity_fragment, container, false);
Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/androidnation_b.ttf");
TextView txt = (TextView) view.findViewById(R.id.textView1);
txt.setTypeface(font);

return view;