我有一个扩展的EditText,在以下情况下我无法调用任何标准函数:
MainActivity
private Editor sEditor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ex);
sEditor = (Editor)findViewById(R.id.s_editor);
}
private String retText() {
return sEditor.getText.toString();
}
编辑
public Editor(Context context) {
super(context);
init();
}
public Editor(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public Editor(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
}
调用retText()时:
Attempt to invoke virtual method 'android.text.Editable com.paulo.ex.Editor.getText()' on a null object reference
我还尝试将编辑器初始化为sEditor = new Editor(MainActivity.this);
,但retText()的返回值始终为null。解决此问题的适当方法是什么?