活动空对象引用

时间:2019-08-21 12:51:35

标签: java android-studio nullpointerexception

我正在设置kisok应用程序,并在我的WebviewActivity中不断获取java.lang.NullPointerException。

Unable to start activity ComponentInfo{eu.xx.xyc/eu.xx.xyz.ActivityWebView}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.addTextChangedListener(android.text.TextWatcher)' on a null object reference

检查xml中的“视图”而不是“视图”声明。检查对象是否具有值,以及对象是否被实例化。看过Stackoverflow,但给定的解决方案对我不起作用。

        <EditText
            android:layout_width="289dp"
            android:layout_height="wrap_content"
            android:inputType="textUri"
            android:text="@string/not_set"
            android:id="@+id/remoteContentURLTextField"
            android:layout_below="@+id/remoteContentURL"
            android:layout_alignParentStart="true" />

private EditText mRemoteContentURLEditText;

protected void onCreate(Bundle savedInstanceState) {

 setContentView(R.layout.activity_web_view);

connectUiElements();
setUpUiListeners();
}
 private void connectUiElements() {
        mRemoteContentURLEditText = (EditText) findViewById(R.id.remoteContentURLTextField);
}
mRemoteContentURLEditText.addTextChangedListener(
                new TextWatcher() {

                    @Override
                    public void afterTextChanged(Editable s) {
                    }

                    @Override
                    public void beforeTextChanged(CharSequence s, int start,
                                                  int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence newValue, int start,
                                              int before, int count) {
                        updateRemoteContentURL(newValue.toString());
                    }
                }
        );

        mRemoteContentURLEditText.setOnEditorActionListener(

                new EditText.OnEditorActionListener() {
                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        return false; // pass on to other listeners.
                    }
                }
        );

我希望它可以正常构建,并且不能为null。

感谢帮助。

0 个答案:

没有答案
相关问题