class IconicAdapter extends ArrayAdapter<String> {
Activity context=new Activity();
IconicAdapter(Activity context) {
super(context, R.layout.topic_list_row, itemList);
this.context = context;
LayoutInflater inflater = context.getLayoutInflater();
}
public View getView(int position, View convertView, ViewGroup parent) {
// View row = convertView;
ViewHolder holder = null;
LayoutInflater inflater = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.topic_list_row, null);
holder = new ViewHolder();
holder.textView = (TextView)convertView.findViewById(R.id.label);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
Typeface face=Typeface.createFromAsset(getAssets(), "MS-I034.TTF");
holder.textView.setTypeface(face);
holder.textView.setText(getModel(position));
return convertView;
}
错误:
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): FATAL EXCEPTION: main
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): java.lang.NullPointerException
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at com.webrich.bachflower.Topics$IconicAdapter.getView(Topics.java:113)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.widget.ListView.onMeasure(ListView.java:1127)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.view.View.measure(View.java:8313)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.view.View.measure(View.java:8313)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.view.View.measure(View.java:8313)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.view.View.measure(View.java:8313)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.view.View.measure(View.java:8313)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.os.Looper.loop(Looper.java:123)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at java.lang.reflect.Method.invoke(Method.java:507)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-02 11:29:53.010: ERROR/AndroidRuntime(1043): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
试试这个
public View getView(int position, View convertView, ViewGroup parent) {
// View row = convertView;
ViewHolder holder = null;
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.topic_list_row, null);
holder = new ViewHolder();
holder.textView = (TextView)convertView.findViewById(R.id.label);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
Typeface face=Typeface.createFromAsset(getAssets(), "MS-I034.TTF");
holder.textView.setTypeface(face);
holder.textView.setText(getModel(position));
return convertView;
}