【问题标题】:NullPointerException - What to do?NullPointerException - 怎么办?
【发布时间】:2012-03-18 22:27:04
【问题描述】:

我在这段代码中遇到了 NullpointerException:

kuglebutton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(toggle.isChecked())
            {                   
                counter1 = counter1 + 10;
                column1tv.setText("" + counter1);                   
            }
            else
            {           
                counter1 = counter1 - 2;
                column1tv.setText("" + counter1);           
            }
        }                   
});

谁能告诉我我做错了什么,也许如何解决?

【问题讨论】:

  • kuglebutton 或 toogle 或 column1tv 为空。
  • 查看异常的堆栈跟踪,看看是哪一行代码生成的
  • 放Logacat,你的完整代码....
  • -1 缺乏信息和研究工作。 developer.android.com/guide/developing/debugging/…
  • -1 表示没有响应上述任何 cmets

标签: android nullpointerexception togglebutton


【解决方案1】:

正如黑带所说,有些东西是空的。使用 logcat 可以准确查看异常发生的位置。当你找到这个地方时,问题有时很明显。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    • 2019-11-18
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    相关资源
    最近更新 更多