2012-09-20 43 views
0

我的應用程序啓動畫面設置爲讓一個圖像淡入,然後是另一個圖像,然後在第二個圖像完成後,設置爲啓動我的主要活動。Android;應用程序已停止。簡單的動畫錯誤

一旦我的第二張圖像幾乎完成淡入,它就會崩潰。

這是我的SplashScreen活動;

package com.example.gymbuddy; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.animation.Animation; 
import android.view.animation.Animation.AnimationListener; 
import android.view.animation.AnimationUtils; 
import android.widget.ImageView; 

public class SplashScreen extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_splashscreen); 

    ImageView gym = (ImageView) findViewById(R.id.imageView1); 
    Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.gym); 
    gym.startAnimation(fade1); 

    ImageView buddy = (ImageView) findViewById(R.id.imageView2); 
    Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.buddy); 
    buddy.startAnimation(fade2); 
     fade2.setAnimationListener(new AnimationListener() { 

      public void onAnimationStart(Animation animation) { 

      } 

      public void onAnimationEnd(Animation animation) { 
       Intent intent = new Intent(SplashScreen.this, Main.class); 
       SplashScreen.this.startActivity(intent); 
       SplashScreen.this.finish(); 
      } 

      public void onAnimationRepeat(Animation animation) { 

      } 
     }); 
} 

@Override 
public void onPause() { 
    ImageView gym = (ImageView) findViewById(R.id.imageView1); 
    gym.clearAnimation(); 

    ImageView buddy = (ImageView) findViewById(R.id.imageView2); 
    buddy.clearAnimation(); 

} 

} 
+0

請給我們一個logcat的或崩潰的堆棧跟蹤。 – Stericson

回答

0

我敢打賭,這是兩件事之一。

要麼Main.class不存在

OR

Main.class在你的清單作爲一項活動未聲明。

你應該有這樣的事情在你的清單:

<activity android:name=".Main" android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
</activity> 
+0

雖然。我拿出了處理onAnimationEnd的整段代碼,只剩下 Intent intent = new Intent(SplashScreen.this,Main.class); SplashScreen.this.startActivity(intent); SplashScreen.this.finish(); 現在它直接到我的Main.Class(可預測,因爲它不等待動畫結束)這是爲了確保我的意圖和類字段正常工作。 –

+0

你還拿出onPause()嗎?也許問題出在那裏...... logcat或stacktrace可以讓我們指出問題所在。 – Stericson

+0

我拿出了onPause(),現在一切正常!謝謝! 任何人都可以解釋爲什麼這是?如果用戶現在在動畫中點擊回家,會發生什麼情況? –

相關問題