解决方案 »

  1.   

    TextView myTextView=(TextView)findViewById(R.id.myTextview);
    Button  myButton=(Button)findViewById(R.id.myButton);
     myTextView.setText("我的第一个textView");
    myButton.setText("确定");我在程序中删除这两条代码后错误就没有了~
      

  2.   

    报了空指针错误,难道是你的xml文件写得有问题。
    自己检查一下xml文件中Button和TextView的id有没有问题。应该是这儿的问题。
      

  3.   

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.hollow.MainActivity$PlaceholderFragment" >    <TextView
            android:id="@+id/myTextview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ></TextView>
               
        <Button
            android:id="@+id/myButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />  
        
    </RelativeLayout>
      

  4.   

    那几行代码不要写在oncreate里,放到fragment的oncreateview里。
      

  5.   

     myTextView.setText("wo");
      myButton.setText("queding");
    当我删除这两条代码的时候,程序可以运行
      

  6.   


    我试了下:报错了Cannot make a static reference to the non-static method findViewById(int) from the type Activity
      

  7.   

    我试了下:报错了Cannot make a static reference to the non-static method findViewById(int) from the type Activity
      

  8.   

    我一般这么做。只留Activity_main类和对应的xml,把fragment对应的类和xml删除。另外所有组件定义到activity的xml中。
    这个样子,获取组件肯定OK的。
      

  9.   

    http://bbs.csdn.net/topics/390764851
      

  10.   

    目测是setContentView();这句代码问题,不信不看看。
      

  11.   

    获取myTextView之后,判断是否为空
    加上try catch 查看具体异常原因
      

  12.   

    http://bbs.csdn.net/topics/390742254,因为两个控件是空指针,所以你删除对两个控件实现的方法的时候就不会报错了,,,