我不斷收到空指針錯誤,但我找不出原因。有什麼非常明顯的我失蹤了嗎?安卓文本在TextView上設置錯誤
final Dialog d = new Dialog(Start.this);
// dialog.requestWindowFeature((int) Window.FEATURE_NO_TITLE);
d.requestWindowFeature((int) android.view.Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.popuptwo);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
d.show();
d.getWindow().setAttributes(lp);
TextView totaltxt = (TextView) findViewById(R.id.totaltxt);
totaltxt.setText("Test text");
如果我刪除totaltxt.setText("Test text");
則程序不會崩潰。想法?
後堆棧跟蹤...... – njzk2
(但我的猜測是,你需要調用d.findViewById) – njzk2
確實有totaltxt的TextView在popuptwo佈局? – crbin1