0
我閃屏綿延厲害,當我跑我的應用程序,所以我想在這裏的問題進行手動調整抖動一個解決方案,並清除像這樣不能在開機畫面找到線性佈局 - 空指針異常
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
BitmapFactory.Options myOptions = new BitmapFactory.Options();
myOptions.inDither = true;
myOptions.inScaled = false;
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
myOptions.inDither = false;
myOptions.inPurgeable = true;
Bitmap preparedBitmap = BitmapFactory.decodeResource(getApplication()
.getResources(), R.drawable.bg, myOptions);
Drawable background = new BitmapDrawable(preparedBitmap);
((LinearLayout) findViewById(R.id.layout_main))
.setBackgroundDrawable(background);
而不是把導致不良拉伸的飛濺的形象,我設置背景和配置選項。 我的XML看起來像這樣
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout_main">
</LinearLayout>
我試圖清理+重建+刷新,但仍然在我
((LinearLayout) findViewById(R.id.layout_main))
.setBackgroundDrawable(background);
得到一個NullPointerException它不能找到線性佈局。有任何想法嗎?幫幫我!
出於好奇,你確定'Drawable background'沒有返回一個'null'對象嗎?試着將這個'findViewById'語句拆分成不同的步驟。 'LinearLayout ll = findViewById(R ...);'then'll.setBackgroundDrawable(..)'。在兩者之間插入'null'檢查以查看生成NPE的_exactly_。 – 2012-02-09 03:01:41
它在LinearLayout ll - 基本上findViewById返回null – Slartibartfast 2012-02-09 09:49:00