这是classBinderData扩展BaseAdapter的getView函数:
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null) {
vi = inflater.inflate(R.layout.list_row, null);
holder = new ViewHolder();
holder.name = (TextView) vi.findViewById(R.id.name);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
Typeface tf = Typeface.createFromAsset(vi.getContext().getAssets(), "fonts/Roboto_Thin.ttf");
holder.name.setTypeface(tf);
return vi;
}`
添加行:Typeface tf = Typeface.createFromAsset(vi.getContext().getAssets(), "fonts/Roboto_Thin.ttf");
使应用程序崩溃。
那么如何设置字体呢?
编辑
日志猫
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.myapp.BinderData.getView(BinderData.java:65)
at android.widget.AbsListView.obtainView(AbsListView.java:2045)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
at android.widget.ListView.onMeasure(ListView.java:1155)
at android.view.View.measure(View.java:12853)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4806)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1386)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:677)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:558)
at android.view.View.measure(View.java:12853)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4806)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:298)
at android.view.View.measure(View.java:12853)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:829)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:558)
at android.view.View.measure(View.java:12853)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4806)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:298)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2111)
at android.view.View.measure(View.java:12853)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1065)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2455)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)