0

我試圖讓一個viewflipper翻轉。似乎在正常的活動中工作,但是當我把所有東西都變成碎片時,我一直在收到NPE。NullPointerException與setAnimationListener()在FragmentActivity

這裏是我的代碼:

Animation in, out; 
ViewFlipper customActionBarFlipper; 

MyFragmentActivity mfa = MyFragmentActivity.this; 
Context ctx = mfa; //Originally I was using this context in the loadAnimation. 

in = AnimationUtils.loadAnimation(getBaseContext(), R.anim.push_left_in_80); 
out = AnimationUtils.loadAnimation(getBaseContext(), R.anim.push_left_out_80); 

in.setAnimationListener(mfa); 
out.setAnimationListener(mfa); 

customActionBarFlipper.setInAnimation(in); 
customActionBarFlipper.setOutAnimation(out); 

我有一個很好的感覺,我只是忘記明顯,但睡眠不足是殺手。如果任何人都可以如此善良,並把我推向正確的方向,那將不勝感激。

如果你想看到更多的代碼,我會很樂意提供它。我認爲這應該夠了。具有腳蹼的佈局也是充氣的。

謝謝!

+0

你能粘貼錯誤日誌嗎? – 2013-02-20 05:46:09

+0

不需要! :)在通過我的代碼時發現問題,我在查找id之前曾經誇大了我需要的內容。腳在口中! – user1457114 2013-02-20 06:24:17

回答

0

您的customActionBarFlipper未在任何地方初始化。您只需創建它,然後嘗試在不初始化的情況下使用它。這使它爲空,並且導致NullPointerException

您的鰭狀肢可能在充氣佈局中可用,但您仍必須獲得對其的引用。

+1

就是你說的。我發現,然後膨脹。我在隨機時間對這兩個編碼進行了編碼,並丟失了我放置它們的位置......抱歉打擾了所有人!儘管謝謝你的幫助! – user1457114 2013-02-20 06:23:37

相關問題