1. <small id='b0FtK'></small><noframes id='b0FtK'>

    <tfoot id='b0FtK'></tfoot>
    1. <i id='b0FtK'><tr id='b0FtK'><dt id='b0FtK'><q id='b0FtK'><span id='b0FtK'><b id='b0FtK'><form id='b0FtK'><ins id='b0FtK'></ins><ul id='b0FtK'></ul><sub id='b0FtK'></sub></form><legend id='b0FtK'></legend><bdo id='b0FtK'><pre id='b0FtK'><center id='b0FtK'></center></pre></bdo></b><th id='b0FtK'></th></span></q></dt></tr></i><div id='b0FtK'><tfoot id='b0FtK'></tfoot><dl id='b0FtK'><fieldset id='b0FtK'></fieldset></dl></div>
      <legend id='b0FtK'><style id='b0FtK'><dir id='b0FtK'><q id='b0FtK'></q></dir></style></legend>

        <bdo id='b0FtK'></bdo><ul id='b0FtK'></ul>

    2. android 中 findViewById() 上的 NullPointerException

      NullPointerException on findViewById() in android(android 中 findViewById() 上的 NullPointerException)
      <i id='Zu5Oh'><tr id='Zu5Oh'><dt id='Zu5Oh'><q id='Zu5Oh'><span id='Zu5Oh'><b id='Zu5Oh'><form id='Zu5Oh'><ins id='Zu5Oh'></ins><ul id='Zu5Oh'></ul><sub id='Zu5Oh'></sub></form><legend id='Zu5Oh'></legend><bdo id='Zu5Oh'><pre id='Zu5Oh'><center id='Zu5Oh'></center></pre></bdo></b><th id='Zu5Oh'></th></span></q></dt></tr></i><div id='Zu5Oh'><tfoot id='Zu5Oh'></tfoot><dl id='Zu5Oh'><fieldset id='Zu5Oh'></fieldset></dl></div>
          <bdo id='Zu5Oh'></bdo><ul id='Zu5Oh'></ul>

          <small id='Zu5Oh'></small><noframes id='Zu5Oh'>

          <legend id='Zu5Oh'><style id='Zu5Oh'><dir id='Zu5Oh'><q id='Zu5Oh'></q></dir></style></legend>

            <tfoot id='Zu5Oh'></tfoot>

                  <tbody id='Zu5Oh'></tbody>
                本文介绍了android 中 findViewById() 上的 NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在下面的代码中,我在第 9/10 行使用 findViewById() 得到 NullPointerException.
                在我的主类中,我只是从这个类中实例化了一个对象,以使用 .getFrom()

                In the following code i get a NullPointerException on lines 9/10 with findViewById().
                In my main class I just instantiated an object from this class, to use .getFrom()

                public class UserInteraction extends Activity {
                EditText etFrom;
                int from;
                EditText etTill;
                int till;
                
                public UserInteraction(){
                    etFrom = (EditText)findViewById(R.id.et_from);
                    etTill = (EditText)findViewById(R.id.et_till);
                }
                
                public int getFrom() {
                    String s = etFrom.getText().toString();
                    int i = Integer.parseInt(s);
                    return i;
                }
                
                public int getTill() {
                    String s = etTill.getText().toString();
                    int i = Integer.parseInt(s);
                    return i;
                }
                

                是不是我的主类中设置了 contentView ..?可能是什么原因?

                Is it that the contentView is set in my main class ..? What could be the cause ?

                推荐答案

                setContentView 方法应该在调用 findViewById 之前以适当的布局调用之前.它通常在 onCreate(Bundle savedInstance) 方法中调用.

                The setContentView method should be called with appropriate layout before calling findViewById. It is usually called in onCreate(Bundle savedInstance) method.

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

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  <tbody id='QWQaB'></tbody>
                <legend id='QWQaB'><style id='QWQaB'><dir id='QWQaB'><q id='QWQaB'></q></dir></style></legend>
                    <bdo id='QWQaB'></bdo><ul id='QWQaB'></ul>
                  • <small id='QWQaB'></small><noframes id='QWQaB'>

                    <i id='QWQaB'><tr id='QWQaB'><dt id='QWQaB'><q id='QWQaB'><span id='QWQaB'><b id='QWQaB'><form id='QWQaB'><ins id='QWQaB'></ins><ul id='QWQaB'></ul><sub id='QWQaB'></sub></form><legend id='QWQaB'></legend><bdo id='QWQaB'><pre id='QWQaB'><center id='QWQaB'></center></pre></bdo></b><th id='QWQaB'></th></span></q></dt></tr></i><div id='QWQaB'><tfoot id='QWQaB'></tfoot><dl id='QWQaB'><fieldset id='QWQaB'></fieldset></dl></div>
                        <tfoot id='QWQaB'></tfoot>