市販のアプリからダイアログのTextViewにエラーが発生しました。エラーは
java.lang.NullPointerException
at com.b2creativedesigns.eyetest.ColorBlindTest1$2.onClick(ColorBlindTest1.java:324)
部分的なコードは次のとおりです。
btnNext1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GlobalVars.setPoints(points);
dialog = new Dialog(ColorBlindTest1.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.cbtdialog);
TextView dialogtext = (TextView) dialog.findViewById (R.id.tvCBTresult);
TextView dialogtext2 = (TextView) dialog.findViewById (R.id.tvCBTresult2);
Button btnQuit = (Button) dialog.findViewById (R.id.btnCTBback);
Button btnFB = (Button) dialog.findViewById (R.id.btnCBTFB);
Button btnMarket = (Button) dialog.findViewById (R.id.btnCBTMarket);
if (points >= 14)
{
dialogtext.setText("Your result is " + points + "/15!");
dialogtext.setTextColor(Color.rgb(19, 20, 111));
dialogtext2.setText("Something"); //error line
}
...
私の質問は
ここでオブジェクト(TextViewの場合)をローカルで宣言し、グローバルに外部で宣言して
TextView dialogtext2;
ここにのみ書き込むことは問題ありませんか?dialogtext2 = (TextView) dialog.findViewById (R.id.tvCBTresult2);
?
4つの密度に対して4つのフォルダーがあります:layout-ldpi、layout-mdpi、layout-hdpi、layout-xhdpi。layout-xhdpiフォルダーのxmlには、dialogtext2TextViewが含まれていませんでした。これによりエラーが発生する可能性がありますか?別の密度フォルダーの同じxmlからオブジェクトが欠落している場合、Androidは別の密度フォルダーのxmlを適用しませんか?
他に何がエラーの原因になる可能性がありますか?