何かを試すために、ビューの背景を赤に設定しようとしています。アクティビティレイアウトにビューを追加し、ID「gradientView」を付けました。私のJavaコードでは、次のような新しいビューを作成します。
View gradientView = (View) findViewById(R.id.gradientView);
そしてonCreateで私はこれを行います:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_clean_weather);
gradientView.setBackgroundColor(Color.RED);
何らかの理由で、findViewByIdでNullPointerExceptionが発生します。XMLのビューを参照したときに、「nullではない」と思ったのですか?!
誰かが何が起こっているのか知っていますか?
ありがとう。