我将在我的项目中使用askerov的dynamicgridview库,但是当我测试应用程序时,我有时会得到nullpointerexception。我的gridview中有100个项目,当我将项目拖到底部时。最后7行没有动画和应用程序崩溃如下。当我有84项最后5行时,不要动画和应用程序崩溃。最后,当我有50或少于50项时,最后2行没有动画和应用程序崩溃。
我尝试使用try catch但是库崩溃了不同的代码行。我尝试更换适配器。等;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
CheeseViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(
R.layout.grid_item, null);
holder = new CheeseViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (CheeseViewHolder) convertView.getTag();
}
holder.build(getItem(position).toString());
return convertView;
}
我为每个项目设置了不同的标签。 App崩溃的细胞动画部分。我没有解决这个问题。你是怎么解决这个问题的?
private Point getColumnAndRowForView(View view) {
int pos = getPositionForView(view);
int columns = getColumnCount();
int column = pos % columns;
int row = pos / columns;
return new Point(column, row);
}
03-22 12:26:55.309: E/AndroidRuntime(9461): FATAL EXCEPTION: main
03-22 12:26:55.309: E/AndroidRuntime(9461): java.lang.NullPointerException
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.widget.AdapterView.getPositionForView(AdapterView.java:600)
03-22 12:26:55.309: E/AndroidRuntime(9461): at net.mertsaygi.ustalibrary.DynamicGridView.getColumnAndRowForView(DynamicGridView.java:904)
03-22 12:26:55.309: E/AndroidRuntime(9461): at net.mertsaygi.ustalibrary.DynamicGridView.handleCellSwitch(DynamicGridView.java:690)
03-22 12:26:55.309: E/AndroidRuntime(9461): at net.mertsaygi.ustalibrary.DynamicGridView.access$14(DynamicGridView.java:681)
03-22 12:26:55.309: E/AndroidRuntime(9461): at net.mertsaygi.ustalibrary.DynamicGridView$2.checkAndHandleFirstVisibleCellChange(DynamicGridView.java:1097)
03-22 12:26:55.309: E/AndroidRuntime(9461): at net.mertsaygi.ustalibrary.DynamicGridView$2.onScroll(DynamicGridView.java:1027)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1520)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5552)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4677)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.view.Choreographer.doFrame(Choreographer.java:524)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.os.Handler.handleCallback(Handler.java:615)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.os.Handler.dispatchMessage(Handler.java:92)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.os.Looper.loop(Looper.java:137)
03-22 12:26:55.309: E/AndroidRuntime(9461): at android.app.ActivityThread.main(ActivityThread.java:4960)
03-22 12:26:55.309: E/AndroidRuntime(9461): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 12:26:55.309: E/AndroidRuntime(9461): at java.lang.reflect.Method.invoke(Method.java:511)
03-22 12:26:55.309: E/AndroidRuntime(9461): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
03-22 12:26:55.309: E/AndroidRuntime(9461): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
03-22 12:26:55.309: E/AndroidRuntime(9461): at dalvik.system.NativeStart.main(Native Method)