2011-11-03 79 views
0

我开始此活动时,我的应用程序崩溃。我在我的布局中定义了一个编辑文本,并在我的活动的onCreate内部实例化。我正在为我的Edittext创建监听器。Edittext addTextChangedListener崩溃

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 

      } 
     }); 
+1

你可以发布堆栈跟踪吗? – Damian

+1

你可以发布logcat输出,所以我们可以看到堆栈跟踪? – Chris

回答

0

问题不在于EditText。这是由于我发现使用LogCat的其他一些问题。感谢您的建议使用LogCat。

0

没有堆栈跟踪这是很难说的问题是什么。如果我不得不猜测,我会说当你调用mTextView.setInputType(InputType.TYPE_CLASS_TEXT);时你会得到一个NullPointerException异常。这将由findViewById retuning null引起,因为它无法在您的活动中找到具有给定ID的任何视图。您在发布的代码之前是否拨打了setContentView(int layoutId)?另外,如果您已经调用了setContentView,那么您确定在该调用中您正在膨胀的布局实际上包含EditText小部件,并带有edit_text的id?