android-位于对话框上的EditText上的NullPointerException

android-位于对话框上的EditText上的NullPointerException,第1张

概述这是我的email_dialog.xml布局:<LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"

这是我的email_dialog.xml布局:

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:orIEntation="vertical" ><tableRow    androID:ID="@+ID/tableRow0"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content" ></tableRow><tableRow    androID:ID="@+ID/tableRow1"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content" >    <EditText        androID:ID="@+ID/txtEmailAddress5"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:inputType="textEmailAddress"         androID:text="[email protected]"/></tableRow>   <tableRow    androID:ID="@+ID/tableRow2"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content" >       <button           androID:ID="@+ID/btnCancelEmail"           androID:layout_wIDth="wrap_content"           androID:layout_height="wrap_content"           androID:wIDth="200px"           androID:text="Cancel" />       <button           androID:ID="@+ID/btnOkEmail"           androID:layout_wIDth="wrap_content"           androID:layout_height="wrap_content"           androID:wIDth="200px"           androID:text="Email" /></tableRow>

这是我调用和使用它的方法:

voID showEmailDialog() {    // Final prevents the error in the newest onClick callback.    final Dialog dialog = new Dialog(this);    dialog.setContentVIEw(R.layout.email_dialog);    dialog.setTitle("Enter Email Address");    dialog.setCancelable(true);    final EditText txtEA = (EditText) findVIEwByID(R.ID.txtEmailAddress5);    final button cancelbutton = (button) dialog.findVIEwByID(R.ID.btnCancelEmail);    final button sendbutton = (button) dialog.findVIEwByID(R.ID.btnOkEmail);    // set up cancel button    cancelbutton.setonClickListener(new OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            dialog.dismiss();        }    });    // set up send button    sendbutton.setonClickListener(new OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            Log.d(TAG, "sendbutton onClick()");            String emailAddress;            Log.d(TAG, "sendbutton onClick() - String emailAddress");            Log.d(TAG,                    "sendbutton onClick() - txtEmailAddress = (EditText)");            emailAddress = txtEA.getText().toString();            Log.d(TAG,                    "sendbutton onClick() - emailAddress = getText().toString();");            sendEmail(emailAddress);            dialog.dismiss();        }    });    dialog.show();    //}

正确定义TAG,无需担心.
我不断得到:

txtEA.getText().toString() 

引发空点异常.我有正确的R.ID值,我已经验证了50次,我在尝试访问EditText之前验证了setContentVIEw()是否正确,并且两个带有setonClickListener的button都可以正常工作.

我绝对可以在这上面换另一只眼!我已经研究了类似的问题并尝试了解决方案,但是没有一个解决了我的问题!

解决方法:

你应该做这个:

 final EditText txtEA = (EditText) dialog.findVIEwByID(R.ID.txtEmailAddress5);

您忘记在对话框中搜索txtEA.

总结

以上是内存溢出为你收集整理的android-位于对话框上的EditText上的NullPointerException全部内容,希望文章能够帮你解决android-位于对话框上的EditText上的NullPointerException所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1095228.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存