当我开始此活动时,我的应用程序崩溃。我在布局中定义了一个编辑文本,并在活动的onCreate中实例化。我正在为我的Edittext创建监听程序。
mTextView = (EditText) findViewById(R.id.edit_text);
mTextView.setInputType(InputType.TYPE_CLASS_TEXT);
mTextView.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
});发布于 2011-11-07 12:47:58
这个问题不是由于EditText造成的。这是由于我在使用LogCat时发现的其他一些问题。感谢您对使用LogCat的建议。
发布于 2011-11-04 04:47:34
如果没有堆栈跟踪,就很难判断问题出在哪里。如果非要我猜的话,我会说当你调用mTextView.setInputType(InputType.TYPE_CLASS_TEXT);.时,你得到了一个NullPointerException这可能是由findViewById返回null引起的,因为它在您的活动中找不到任何具有给定id的视图。您在发布代码之前调用过setContentView(int layoutId)吗?另外,如果您调用了setContentView,您确定在该调用中膨胀的布局实际上包含一个id为edit_text的EditText小部件吗?
https://stackoverflow.com/questions/8001381
复制相似问题