刚开始学Android编程,不是很会调试,上面那一堆红色字里面只有蓝色那行点了之后会跳到代码指定的行。

解决方案 »

  1.   

    mTrueButton这个为null
    原因是(Button)findViewById(R.id.true_button);得到的值是null,mTrueButton初始化失败
    估计是true_button这个id所在的xml布局文件和你写的不一样true_button这个id所在的xml布局文件要和setContentView里的一样才行
      

  2.   

    你是说下面这个吗?
    <Button
                android:id="@+id/true_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/true_button"/>
    这id是一样的吧
      

  3.   

    以上代码,只可能是button为空。请检查id与布局文件中是否一致。
      

  4.   

    <Button
                android:id="@+id/true_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/true_button"/>
    你说的是.xml中的上面这写代码吗?这id不写的一样吗?
      

  5.   

    <Button
                android:id="@+id/true_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/true_button"/>
    你说的是.xml中的上面这写代码吗?这id不写的一样吗?把oncreate中的代码都贴出来。
      

  6.   

    你是说下面这个吗?
    <Button
                android:id="@+id/true_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/true_button"/>
    这id是一样的吧setContentView的参数是一个R.layout.XXX的布局文件
    而你这个true_button的id也要在这个名为XXX的布局文件里面很容易发生错误是:
    例如true_button在fragment_main.xml
    结果setContentView里写的是:setContentView(R.layout.activity_main)……
    虽然编译器没报错,但是运行就会出空指针
      

  7.   

    你是说下面这个吗?
    <Button
                android:id="@+id/true_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/true_button"/>
    这id是一样的吧setContentView的参数是一个R.layout.XXX的布局文件
    而你这个true_button的id也要在这个名为XXX的布局文件里面很容易发生错误是:
    例如true_button在fragment_main.xml
    结果setContentView里写的是:setContentView(R.layout.activity_main)……
    虽然编译器没报错,但是运行就会出空指针
    大神,是这个原因。
    那是怎么改?
    是把setContentView(R.layout.activity_main)直接改成setContentView(R.layout.fragment_main)?程序还是崩溃啊?
      

  8.   

    你的意思是true_button在fragment_main里,但是你用setContentView(R.layout.fragment_main)还是崩溃?
    错误一样么?
    贴代码吧……这样表述效率太低了……
    布局文件和oncreate的代码,报的错如果不一样,报错原因和所在位置的代码也贴上
      

  9.   

    你的意思是true_button在fragment_main里,但是你用setContentView(R.layout.fragment_main)还是崩溃?
    错误一样么?
    贴代码吧……这样表述效率太低了……
    布局文件和oncreate的代码,报的错如果不一样,报错原因和所在位置的代码也贴上

    我的布局文件true_button在fragment_main里
    用setContentView(R.layout.fragment_main)还是崩溃报错不一样,点哪一行都不跳转了
      

  10.   

    你的意思是true_button在fragment_main里,但是你用setContentView(R.layout.fragment_main)还是崩溃?
    错误一样么?
    贴代码吧……这样表述效率太低了……
    布局文件和oncreate的代码,报的错如果不一样,报错原因和所在位置的代码也贴上

    我的布局文件true_button在fragment_main里
    用setContentView(R.layout.fragment_main)还是崩溃报错不一样,点哪一行都不跳转了这个错和前面报的错又不是一个了。
      

  11.   

    错误变了
    估计是:
    java.lang.IllegalArgumentException:No view found for id for fragment 
    你可以看下http://blog.csdn.net/mengliluohua_151/article/details/9012305
    这个解决方案,大概意思好像也是id引用错误……