Android: нулевой указатель на заставке - PullRequest
1 голос
/ 14 ноября 2011

Я делаю приложение, в котором мне нужно реализовать альфа-эффект на заставке, и когда я загружаю изображение, оно дает null pointer exception. Основная проблема при запуске анимации.Анимация не запускается вообще. Я действительно застрял. Любая помощь будет оценена. Мой код выглядит следующим образом:

public class SplashScreen extends Activity {


private Thread mSplashThread;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    System.out.println("hello");
    setContentView(R.layout.splash);

    final SplashScreen sPlashScreen = this; 

    Animation a1 = AnimationUtils.loadAnimation(this, R.anim.alpha);
        LinearLayout Ll=(LinearLayout)findViewById(R.id.mainLayoutheader);
        System.out.println("hello1");
        Ll.startAnimation(a1);
         System.out.println("hello2");


    // The thread to wait for splash screen events
    mSplashThread =  new Thread(){
        @Override
        public void run(){
            try {
                synchronized(this){
                    // Wait given period of time or exit on touch

                   // a.reset();


                    wait(6000);
                }
            }
            catch(InterruptedException ex){                    
            }

            finish();

            // Run next activity
            Intent intent = new Intent();
            intent.setClass(sPlashScreen, Main.class);
            startActivity(intent);
            stop();                    
        }
    };

    mSplashThread.start();        
}

} 

Исключение составляет L1.startAnimation(a1);

Ответы [ 4 ]

2 голосов
/ 14 ноября 2011

Полагаю, вы забыли позвонить setContentView.Это необходимо сделать перед вызовом findViewById [править: здесь проблема не решается]

1 голос
/ 25 апреля 2012

Проблема заключалась в том, что представление, в котором я показывал изображение, было пустым.
super.onCreate (savedInstanceState);

    // Splash screen view
    System.out.println("hello");
    setContentView(R.layout.splash);
    ImageView iv=(ImageView)findViewById(R.id.splashscreen12);
    Animation scaleAnim = AnimationUtils.loadAnimation(this,R.anim.alpha);
    iv.startAnimation(scaleAnim);
    scaleAnim.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationEnd(Animation animation) {
        // Start new activity after some delay
        TimerTask newActivity = new TimerTask() {
            @Override
            public void run() {
                startActivity(new Intent(SplashScreeen.this,CallingActivity.class));
                SplashScreeen.this.finish();

            }
        };
        Timer t = new Timer(false);
        t.schedule(newActivity, 2500);
    }

    @Override
    public void onAnimationRepeat(Animation animation) {
        // DO NOTHING

    }

    @Override
    public void onAnimationStart(Animation animation) {
        // DO NOTHING
    }
});
1 голос
/ 14 ноября 2011

Вы можете попробовать нить таймера ... используйте эту ссылку http://thedevelopersinfo.wordpress.com/2009/10/18/scheduling-a-timer-task-to-run-repeatedly/

1 голос
/ 14 ноября 2011

Ll равно нулю или a1 равно нулю, и startAnimation вызывает исключение. Трассировка полного стека показывает, кто его бросил.

Также:

  • Возможно, вы случайно набрали R.id.mainLayoutheader вместо R.id.mainLayoutHeader.
  • Проверьте правильность имени R.anim.alpha.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...