2013-08-27 48 views
1

因此,這裏是我的崩潰報告從logcat中(注意有我的代碼沒有引用):應用程序崩潰 - 我傷心

08-27 13:04:36.307 8073-8073/com.example.mysandbox E/AndroidRuntime: FATAL EXCEPTION: main 
    java.lang.NullPointerException 
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2919) 
    at android.view.View.getDisplayList(View.java:12833) 
    at android.view.View.getDisplayList(View.java:12880) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057) 
    at android.view.View.getDisplayList(View.java:12775) 
    at android.view.View.getDisplayList(View.java:12880) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057) 
    at android.view.View.getDisplayList(View.java:12775) 
    at android.view.View.getDisplayList(View.java:12880) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057) 
    at android.view.View.getDisplayList(View.java:12775) 
    at android.view.View.getDisplayList(View.java:12880) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057) 
    at android.view.View.getDisplayList(View.java:12775) 
    at android.view.View.getDisplayList(View.java:12880) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057) 
    at android.view.View.getDisplayList(View.java:12775) 
    at android.view.View.getDisplayList(View.java:12880) 
    at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1411) 
    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1359) 
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2367) 
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2239) 
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1872) 
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004) 
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481) 
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) 
    at android.view.Choreographer.doCallbacks(Choreographer.java:562) 
    at android.view.Choreographer.doFrame(Choreographer.java:532) 
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) 
    at android.os.Handler.handleCallback(Handler.java:730) 
    at android.os.Handler.dispatchMessage(Handler.java:92) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:5103) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:525) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
    at dalvik.system.NativeStart.main(Native Method) 

,這裏是動畫我快:

import android.view.View; 
import android.view.animation.AccelerateInterpolator; 
import android.view.animation.Animation; 
import android.view.animation.AnimationSet; 
import android.view.animation.Transformation; 
import android.view.animation.TranslateAnimation; 
import android.widget.LinearLayout; 

public class DeleteAnim extends AnimationSet { 

    public View v; 
    int initialHeight; 

    public DeleteAnim(View view) { 
     super(false); 
     v = view; 
     initialHeight = view.getMeasuredHeight(); 

     this.setFillEnabled(true); 

     TranslateAnimation anim1 = new TranslateAnimation(0F, 500F, 0F, 0F); 
     anim1.setInterpolator(new AccelerateInterpolator(1.5F)); 
     anim1.setDuration(150); 
     anim1.setFillAfter(true); 

     this.addAnimation(anim1); 


     Animation anim2 = new Animation() { 

      @Override 
      protected void applyTransformation(float interpolatedTime, Transformation t) { 
       super.applyTransformation(interpolatedTime, t); 

       v.getLayoutParams().height = Math.round(initialHeight * interpolatedTime); 
       v.requestLayout(); 
      } 
     }; 

     anim2.setStartOffset(150); 
     anim2.setDuration(350); 

     this.setFillAfter(true); 

     this.setAnimationListener(new Animation.AnimationListener() { 

      @Override 
      public void onAnimationStart(Animation animation) { 

      } 

      @Override 
      public void onAnimationEnd(Animation animation) { 
       DeleteAnim anim = (DeleteAnim) animation; 
       ((LinearLayout) anim.v.getParent()).removeView(anim.v); 
      } 

      @Override 
      public void onAnimationRepeat(Animation animation) { 

      } 
     }); 
    } 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     if (interpolatedTime == 1) { 
      v.setVisibility(View.GONE); 
     } else { 
      v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime); 
      v.requestLayout(); 
     } 
    } 
} 

我很想知道這裏有什麼不對,如果有人可以幫忙。此外,我只嘗試在API 18中運行它,並且一旦動畫開始就崩潰。

在此先感謝!

+0

你正在測試什麼設備?另請嘗試關閉硬件加速。 – FoamyGuy

+0

在模擬器上測試,在清單文件中是硬件加速選項嗎? –

回答

2

我猜這是因爲你正在移除AnimationEnd調用的視圖。堅持一些登錄/和或獲得Android源,並進入該。

+0

我刪除了它,它不再崩潰:)但它不會做第二個動畫,只有第一個。 –