我正在设计一个应用程序,其中我使用了自定义 ArrayAdapter 并覆盖了 getView() 方法以填充 GridView 的子类。当我运行它时,我得到一个 NullPointer,我相当确定这是因为 Choreographer 中名为“callbacks”的变量为空。我的调试设置显示“回调”和“下一个”(下一个要使用的回调)都为空。我对 Choreographer 的工作原理不太了解,但我尝试查看所有 Choreographer 源代码,但我无法准确弄清楚回调是如何创建的,以及为什么我的程序没有创建任何回调。我尝试将我的自定义 ArrayAdapter 换成普通的,只是为了检查问题出在我的适配器上,情况就是这样。
自定义适配器:
public class SpaceArrayAdapter extends ArrayAdapter<Space>{
Context context;
int resource;
ArrayList<Space> spaces;
public SpaceArrayAdapter(Context context, int resource, ArrayList<Space> spaces){
super(context, resource, spaces);
this.context = context;
this.resource = resource;
this.spaces = spaces;
}//ends LevelSelectorAdapter()
public static class ViewHolder{
public SpaceView view;
}//ends Class ViewHolder
@Override
public View getView(int position, View convertView, ViewGroup parent){
View view = convertView;
ViewHolder holder;
if(view == null){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(resource, null);
holder = new ViewHolder();
holder.view = (SpaceView)view.findViewById(R.id.Space);
view.setTag(holder);
view.setOnClickListener(spaces.get(position).getBoard());
}
else{
holder = (ViewHolder)view.getTag();
}
final Space space = spaces.get(position);
holder.view.setSpace(space);
return view;
}//ends getView()
}//ends Class
堆栈跟踪:
Choreographer.doCallbacks(int, long) line: 572
Choreographer.doFrame(long, int) line: 532
Choreographer$FrameDisplayEventReceiver.run() line: 735
Handler.handleCallback(Message) line: 730
Choreographer$FrameHandler(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 137
ActivityThread.main(String[]) line: 5103
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 525
ZygoteInit$MethodAndArgsCaller.run() line: 737
ZygoteInit.main(String[]) line: 553
NativeStart.main(String[]) line: not available [native method]
LogCat 唯一说的是一堆消息,都说它跳过了几百帧,并且应用程序在主线程上做的太多了。