出現editext我有一個活動內實現一個活動,並試圖添加onclicklistener它,但它顯示一個錯誤「試圖調用空對象上的虛擬方法引用「,但我檢查了editd的id,它是popupdashboard.xml中的」date_from「,我是否缺少某些東西,是否需要爲popdashboard.xml某處添加引用?無法設置Onclicklistener在彈出
public class DashboardActivity2 extends AppCompatActivity implements View.OnClickListener {
ImageView image;
EditText datefrom,dateto;
TextView amo_today,amo_yest,increase,percent;
private PopupWindow active;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard2);
datefrom = (EditText)findViewById(R.id.date_from);
datefrom.setOnClickListener(this);
dateto = (EditText)findViewById(R.id.date_to);
dateto.setOnClickListener(this);
任何幫助,將不勝感激
可以添加你的Pop代碼在你的活動 –
可能是因爲'date_from'不'activity_dashboard2'佈局。檢查這個http://stackoverflow.com/questions/28193552/null-pointer-exception-on-setonclicklistener – jayeshsolanki93
膨脹popupdashboard.xml查看和從中你可以得到edittext的參考 – Nidhin