2014-06-11 26 views
0

我使用下面的代碼行改變我的android活動的背景圖像,在運行時: private View mainLayout; //global variable
mainLayout = findViewById(R.layout.activity_breath); // getting the layout in onCreate method mainLayout.setBackgroundResource(R.drawable.image); //this line is called in run method of timer.
但我得到我的設備上的致命錯誤,空指針異常時setBackgroundResource功能調用。任何人都可以請建議失敗的原因??異常而改變活動運行的背景圖像

回答

1

試圖找到一個R.layout資源與findViewById()將始終失敗並返回null。使用活動視圖層次結構中存在的R.id資源標識符。

+0

是的,這是做的工作。謝謝 – Maruf