我在blah.startAnimation(anim)上得到一个NullPointerException,它位于LongClickListener中.我想要做的是在DragListener上获取GridLayout中的子项数,并在开始拖动imageview时为所有子项设置动画.由于某种原因,这会返回NullPointerException,
它的来源是:
@Override
public boolean onLongClick(View v) {
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
v.startDrag(null,shadowBuilder,v,0);
deleteAreaForAdapter.setVisibility(View.VISIBLE);
deleteAreaForAdapter.startAnimation(slide_in);
for(int i=0; i
logcat的:
08-14 07:47:18.281 2078-2078/com.matt.cards.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.matt.cards.app,PID: 2078
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.startAnimation(android.view.animation.Animation)' on a null object reference
at com.matt.cards.app.DrawerLongClickListener$1.onLongClick(DrawerLongClickListener.java:169)
at android.view.View.performLongClick(View.java:4474)
at android.view.View$CheckForLongPress.run(View.java:18401)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
谢谢!
编辑:任何人都可以帮忙!?!?!?
最佳答案
你只需要使用
Animation shakeAnim = AnimationUtils.loadAnimation(v.getContext(),R.anim.shake);
代替
Animation shakeAnim = AnimationUtils.loadAnimation(context,R.anim.shake);