NullPointerException 和 findViewById() [英] NullPointerException and findViewById()

查看:69
本文介绍了NullPointerException 和 findViewById()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这是针对 Stack Overflow 上常见问题的规范问题.

Note: This is intended as a canonical question for a commonly seen problem here on Stack Overflow.

我的 Android 应用程序崩溃了.我 从 logcat 中检查堆栈跟踪,发现原因是该行的 NullPointerException

My Android app crashed. I checked the stacktrace from the logcat and found that the cause is a NullPointerException at the line

myEditText.setText(myString);

问题是什么,我该如何解决?

What is the problem and how do I fix it?

推荐答案

您没有初始化 myEditText 引用到活动中的任何 EditText 对象.

you didn't initialize myEditText reference to any EditText Object in the activity which holds it..

请确保您初始化它并在正确的位置使用该语句.

kindly be sure you initialize it and you use that statement in the right place.

这篇关于NullPointerException 和 findViewById()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆